Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jun 30, 2012 11:59 AM by simaster99
Member
2 Points
9 Posts
Jun 29, 2012 04:58 PM|LINK
Hi,
Just a link to a tutoria would be cool....
How can I use the auto incramented field from the database to display the row number of the next availble row?
Too add data to the table i use the following method.....
cmd = new SqlCommand("insert into manu values('" + TextBox1.Text + "','" + TextBox2.Text + "')", con); cmd.ExecuteNonQuery();
many thanks
All-Star
15346 Points
3142 Posts
Jun 29, 2012 05:03 PM|LINK
the best way have a int column with Auto Identity
Star
8976 Points
1659 Posts
Jun 29, 2012 07:56 PM|LINK
Since you listed ASP.NET, I'm going to assume you are running a SQL Server 2005/2008. If you want to use the GUI, then follow these steps:
These Links will help..
Good luck`
Jun 30, 2012 10:05 AM|LINK
Hi Guys this returns this error...
Cannot insert explicit value for identity column in table 'berths' when IDENTITY_INSERT is set to OFF.
protected void Page_Load(object sender, EventArgs e) { } SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\ASPNETDB.MDF;Integrated Security=True;Connect Timeout=30;User Instance=True;"); protected void Button1_Click(object sender, EventArgs e) { SqlCommand cmd = new SqlCommand("INSERT INTO berths (berths)VALUES (@berths)", con); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@berths", TextBox1.Text); con.Open(); cmd.ExecuteNonQuery(); con.Close(); } }
-------------------------- BUT ---------------------------------
I would like the form to show the next id number from the database. And not let the user insert an Idenity number.
Many thanks agian
Sim
Jun 30, 2012 11:59 AM|LINK
protected void Button1_Click(object sender, EventArgs e) { SqlCommand cmd = new SqlCommand("SET IDENTITY_INSERT berths ON INSERT INTO berths (berths)VALUES (@berths)", con); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@berths", TextBox1.Text); con.Open(); cmd.ExecuteNonQuery(); con.Close(); } }
adding to the sql command SET IDENTITY_INSERT berths ON this seems to work
simaster99
Member
2 Points
9 Posts
Using auto incrament as text
Jun 29, 2012 04:58 PM|LINK
Hi,
Just a link to a tutoria would be cool....
How can I use the auto incramented field from the database to display the row number of the next availble row?
Too add data to the table i use the following method.....
cmd = new SqlCommand("insert into manu values('" + TextBox1.Text + "','" + TextBox2.Text + "')", con); cmd.ExecuteNonQuery();many thanks
Mudasir.Khan
All-Star
15346 Points
3142 Posts
Re: Using auto incrament as text
Jun 29, 2012 05:03 PM|LINK
the best way have a int column with Auto Identity
MahadTECH
Star
8976 Points
1659 Posts
Re: Using auto incrament as text
Jun 29, 2012 07:56 PM|LINK
Since you listed ASP.NET, I'm going to assume you are running a SQL Server 2005/2008. If you want to use the GUI, then follow these steps:
These Links will help..
Good luck`
Mahad Bin Mukhtar
Remember to Mark the replies as Answers
The easiest day was 'yesterday'.
MCP, MCSD
For .NET TECH Blog
simaster99
Member
2 Points
9 Posts
Re: Using auto incrament as text
Jun 30, 2012 10:05 AM|LINK
Hi Guys this returns this error...
Cannot insert explicit value for identity column in table 'berths' when IDENTITY_INSERT is set to OFF.
protected void Page_Load(object sender, EventArgs e) { } SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\ASPNETDB.MDF;Integrated Security=True;Connect Timeout=30;User Instance=True;"); protected void Button1_Click(object sender, EventArgs e) { SqlCommand cmd = new SqlCommand("INSERT INTO berths (berths)VALUES (@berths)", con); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@berths", TextBox1.Text); con.Open(); cmd.ExecuteNonQuery(); con.Close(); } }-------------------------- BUT ---------------------------------
I would like the form to show the next id number from the database. And not let the user insert an Idenity number.
Many thanks agian
Sim
simaster99
Member
2 Points
9 Posts
Re: Using auto incrament as text
Jun 30, 2012 11:59 AM|LINK
protected void Button1_Click(object sender, EventArgs e) { SqlCommand cmd = new SqlCommand("SET IDENTITY_INSERT berths ON INSERT INTO berths (berths)VALUES (@berths)", con); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@berths", TextBox1.Text); con.Open(); cmd.ExecuteNonQuery(); con.Close(); } }adding to the sql command SET IDENTITY_INSERT berths ON this seems to work