×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

(OP)
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

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

Incrementing the Id is something that should be done by SQL Server. Go into SSMS and make the field autoincrement.

Craig Berntson
MCSD, Visual C# MVP, www.craigberntson.com/blog

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

(OP)
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

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

Fix the first issue, then create a new issue for the second. Don't put two issues in the same thread.

Craig Berntson
MCSD, Visual C# MVP, www.craigberntson.com/blog

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

(OP)
OK i am sorry

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close