Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need to increment records by 1 and update this in table How

Status
Not open for further replies.

ahm1985

Programmer
Dec 6, 2012
138
EG
This is my code as following
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FleetManagment
{
public partial class Driver : Form
{
string value1;
string value2;
string value3;
string value4;
private int currrecord=0;
private int totalrecord=0;
private bool insertselected;
DataTable dt = new DataTable();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
SqlConnection con = new SqlConnection();

public Driver(string str1,string str2,string str3,string str4)
{
InitializeComponent();
value1 = str1;
value2 = str2;
value3 = str3;
value4 = str4;

}

private void fillcontrol()
{
textBox1.Text = dt.Rows[currrecord]["DriverID"].ToString();
textBox2.Text = dt.Rows[currrecord]["DriverName"].ToString();
textBox3.Text = dt.Rows[currrecord]["Nationality"].ToString();
textBox4.Text = dt.Rows[currrecord]["Address"].ToString();


}

private void Driver_Load(object sender, EventArgs e)
{
string constr = "Data Source=" + value1 + ";Initial Catalog=" + value2 + ";User ID=" + value3 + ";Password=" + value4 + "";
SqlConnection con = new SqlConnection(constr);
string comdstr = "select * from Driver";
SqlDataAdapter da = new SqlDataAdapter(comdstr, constr);
DataSet ds = new DataSet();
da.Fill(ds, "Driver");
dt = new DataTable();
dt = ds.Tables["Driver"];
currrecord = 0;
totalrecord = dt.Rows.Count;
fillcontrol();
}

private void NextBtn_Click(object sender, EventArgs e)
{

if (ds != null)
{

currrecord++;
if (currrecord >= totalrecord)
{
currrecord = totalrecord - 1;
}


fillcontrol();
label5.Text = currrecord + "of" + totalrecord;

}



}

private void buttoninsert_Click(object sender, EventArgs e)
{


}



}
}
I have driver table this is my fields as following
DriverID INT
DriverName nvarchar50
Nationality nvarchar50
Address nvarchar50
I have form driver have 4 texbox
textbox1 DriverID
textbox2 DriverName
textbox3 Nationality
textbox4 address
this table have two records
when i press buton next (NextBtn_Click)to go third record it not accept
I need next button increase by 1 if record not exist and update this in table
How i do this
example
if i have two records
1 aln american newyork
2 adam british british
when i press next button it ok work in records exist but when i press next button to third record it not accept why
what i need is when press next after 2 it come 3 in text box driver id and update this number in table
How i do that
please help me
 
this what i need to make in next button but not accept

if (ds != null)
{


int currrecord=0;
currrecord++;
if (currrecord >= totalrecord)
{

currrecord = totalrecord - 1;
}



fillcontrol();
label5.Text = currrecord + "of" + totalrecord;

}
else
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
FleetManagment.Fleet fleat = new FleetManagment.Fleet();
string max = fleat.Max_Driver("Data Source=" + value1 + ";Initial Catalog=" + value2 + ";User ID=" + value3 + ";Password=" + value4 + "");
textBox1.Text = max;
FleetManagment.Fleet fleat1 = new FleetManagment.Fleet();
fleat1.InsertDriver("Data Source=" + value1 + ";Initial Catalog=" + value2 + ";User ID=" + value3 + ";Password=" + value4 + "", Convert.ToInt32(textBox1.Text));
fillcontrol();
}

label5.Text = currrecord + "of" + totalrecord;
can any one help me
i write this code under next button but when it come to record is null it not work why
as example
i have two records 1 and 2
next button work when it moved from 1 to 2 but from 2 to 3 not work why and how i solve this proplem
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top