Hi ,
I am new to this forum and new to C# web programming. I am developing LMS (Library Management system) using SQL Server and Visual Studio ver 16. I have an issue with the insertion of data into the database. the same code I used in other pages and work perfectly. put hardcoded values in insert statement and it worked perfectly which means that there is no issue with connection to database so where is the issue? it can be the text boxes etc name and property which i also checked and found correct. code is as follows
I am new to this forum and new to C# web programming. I am developing LMS (Library Management system) using SQL Server and Visual Studio ver 16. I have an issue with the insertion of data into the database. the same code I used in other pages and work perfectly. put hardcoded values in insert statement and it worked perfectly which means that there is no issue with connection to database so where is the issue? it can be the text boxes etc name and property which i also checked and found correct. code is as follows
SignUpNewMemeber:
void SignUpNewMember()
{
try
{
SqlConnection con = new SqlConnection(strcon);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
// SqlCommand cmd = con.CreateCommand();
//cmd.CommandType = CommandType.Text;// beow is the way to write a query like ist put '' then iside we have "" and then isde we have ++ and then inside we have text box name
// cmd.CommandText= "INSERT INTO member_master_tbl values('"++"','"++"','"++"','"++"','"++"','"++"','"++"','"++"','"++"')"
// cmd.CommandText = "INSERT INTO member_master_tbl (full_name,dob,contact_no,email,state,city,pincode,full_address,member_id,password) values ('" + TextBox1.Text.Trim() + "','" + TextBox2.Text.Trim() + "','"+TextBox4.Text.Trim()+"','" + TextBox3.Text.Trim() + "','" + DropDownList1.SelectedItem.Value + "','" + TextBox6.Text.Trim() + "','" + TextBox7.Text.Trim() + "','" + TextBox5.Text.Trim() + "','" + TextBox8.Text.Trim() + "','" + TextBox9.Text.Trim() + "');";
//notr thr col nsmes in the query are case sensitive
String status = "pending";
SqlCommand cmd = new SqlCommand("INSERT INTO member_master_tbl (full_name,dob,contact_no,email,state,city,pincode,full_address,member_id,password,account_status)values(@full_name,@dob,@contact_no,@email,@state,@city,@pincode,@full_address,@member_id,@password,@account_status);", con);
cmd.Parameters.AddWithValue("@full_name", TextBox1.Text.Trim());
cmd.Parameters.AddWithValue("@dob", TextBox2.Text.Trim());
cmd.Parameters.AddWithValue("@contact_no", TextBox3.Text.Trim());
cmd.Parameters.AddWithValue("@email", TextBox4.Text.Trim());
cmd.Parameters.AddWithValue("@state", DropDownList1.SelectedItem.Value);
cmd.Parameters.AddWithValue("@city", TextBox6.Text.Trim());
cmd.Parameters.AddWithValue("@pincode", TextBox7.Text.Trim());
cmd.Parameters.AddWithValue("@full_address", TextBox5.Text.Trim());
cmd.Parameters.AddWithValue("@member_id", TextBox8.Text.Trim());
cmd.Parameters.AddWithValue("@password", TextBox9.Text.Trim());
cmd.Parameters.AddWithValue("@account_status",status);
cmd.ExecuteNonQuery();
con.Close();
Response.Write("<script>alert('Sign Up Successful. Go to User Login to Login');</script>");
}
catch (SqlException ex)
{
Response.Write("<script>alert('" + ex.Message + "');</script>");
}
}
C#: