I have a field which is an auto generated primary key. Now I need to insert a row with this field as one of its column. How should I create "insert" arguments?
It is happening because of the identity field is set to auto increment and you cannot specify the id, it will be assign automatically by your database.
Try to pass null instead of "1".
What are the method required arguments? Is there method overload with other parameters?
phoenix.soft...
0 Points
1 Post
Use auto generate key
Jan 19, 2013 11:09 AM|LINK
I have a field which is an auto generated primary key. Now I need to insert a row with this field as one of its column. How should I create "insert" arguments?
protected void Button1_Click(object sender, EventArgs e) { new DataSet1TableAdapters.MemberTableAdapter().Insert( 1,TextBox5.Text,TextBox6.Text, int.Parse(TextBox8.Text), TextBox9.Text, TextBox10.Text); }I got Error:
"Cannot insert explicit value for identity column in table 'Member' when IDENTITY_INSERT is set to OFF."Actually I shouldn't insert any value for first argument because it's auto generated. but this error appear after using this style:
And I get:
So how should I solve this problem?
I have set
to yes already.
</div> </div>
kaushikmahet...
Contributor
3773 Points
896 Posts
Re: Use auto generate key
Jan 19, 2013 11:49 AM|LINK
remove id field in insert query because id is auto increment then not a pass manually in query...
otherwise post your code here above code not see clearely
Remember to click Mark as Answer on the post that helps to others.
ramramesh
Member
458 Points
158 Posts
Re: Use auto generate key
Jan 19, 2013 12:36 PM|LINK
Set primary key and set is identity yes.But u also finished work
I get:
So how should I solve this problem?
</div> </div>
this MemberTableAdapter().Insert methode was pass parametes count 6.But you sent parameter values count 5 .Su you get this error.
oned_gk
All-Star
36200 Points
7374 Posts
Re: Use auto generate key
Jan 19, 2013 12:43 PM|LINK
Suwandi - Non Graduate Programmer
iluxa.v
Member
215 Points
47 Posts
Re: Use auto generate key
Jan 21, 2013 07:34 AM|LINK
Hi,
It is happening because of the identity field is set to auto increment and you cannot specify the id, it will be assign automatically by your database.
Try to pass null instead of "1".
What are the method required arguments? Is there method overload with other parameters?