Hi, this is my first job in UK, so need bit of help. The problem goes like this. I have an existing SQL database where there are 2 user tables. One contains only field.U_Id(int) not null and other is user_details table where there are fields like user_id(int), username and so on. While I am trying to insert values into the usertable, if i leave the user id field, then it throws an exception that the field cannot contain nulls, which is right but I want to know a way of incrementing the userid by 1 in both tables.
My code goes like this.
string connString = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connString))
{
string insertstr = " insert into ct_user(User_Id,name,password,email)values(@UserId,@UserName,@Password,@email)";
var cmdtext = new SqlCommand(insertstr,conn);
cmdtext.Parameters.AddWithValue("@UserId",0);
cmdtext.Parameters.AddWithValue("@UserName", txtUserName.Text);
cmdtext.Parameters.AddWithValue("@Password", txtPassword.Text);
cmdtext.Parameters.AddWithValue("@Email", txtEmail.Text);
conn.Open();
cmdtext.ExecuteNonQuery();
Console.WriteLine("Your account has been successfully created", conn);
conn.Close();
Thanks and Regards,
Pradeep Khatri