Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
SqlDataAdapter sda2 = new SqlDataAdapter("SELECT max(id)+1 FROM [TBL_CATEGORYCUSTOMERS]  ", sqlcon);
DataTable dt3= new DataTable();
sda2.Fill(dt3);

I need to insert this data to:
C#
textbox.Text;
Posted
Updated 6-Dec-14 5:09am
v3

you can use ExecuteScalar method
C#
using (var cmd = new SqlCommand("SELECT max(id)+1 FROM [TBL_CATEGORYCUSTOMERS] ", sqlcon))
{
    conn.Open();
    textbox.Text = cmd.ExecuteScalar().ToString();

}
 
Share this answer
 
correct first..
SQL
SELECT max(isnull(id,0))+1 FROM [TBL_CATEGORYCUSTOMERS]


And Your answer is according to your procedure, eventually that is a wrong produce....
C#
if(dt3.Rows.Count>0)
{
textbox.Text=dt3.rows[0][0].tostring();
}

you are using the wrong procedure to select the max Id.
For simplest procedure see @DamithSL solution..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900