I need to increment records by 1 and update this in table Ho
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