Hi,
I'm having problems with code to save inputs from a forms textbox to a data base. I have a Window forms with 6 textbox fields and a button click event that will save the input from these 6 textbox fields to my table called User profile that has 7 columns name Fname, Lname, UserName, Email, Pword, RePword, UserNumber. I have not been able to successfully do this the other tutorials i have found on this does not have this problem. I have not added any validation to this becuase i just wanted to get it working before i started adding validation and other things.. to it.. Here is my currect code..
SqlConnection CnNew = new SqlConnection();
CnNew.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Program Files\Microsoft Visual Studio 9.0\VC#\CSharpProjects\MyDiaryVersionOne\MyDiaryVersionOne\MyDiary.mdf;Integrated Security=True;User Instance=True";
SqlCommand CmdSql = new SqlCommand();
string query = "INSERT INTO UserProfile VALUES(Fname,Lname,UserName,Email,Pword,RePword,UserNumber)";
CmdSql.CommandText = query;
CmdSql.CommandType = CommandType.Text;
CmdSql.Parameters.AddWithValue("Fname", TxtbxFname.Text);
CmdSql.Parameters.AddWithValue("Lname", TxtbxLname.Text);
CmdSql.Parameters.AddWithValue("UserName", TxtbxUname.Text);
CmdSql.Parameters.AddWithValue("Email", TxtbxEmail.Text);
CmdSql.Parameters.AddWithValue("Pword", TxtbxPword.Text);
CmdSql.Parameters.AddWithValue("RePword", TxtbxRepword.Text);
CmdSql.Parameters.AddWithValue("UserNumber", TxtbxUname.Text);
CmdSql.Connection = CnNew;
CnNew.Open();
CmdSql.ExecuteNonQuery();
<Will The Great>
I'm having problems with code to save inputs from a forms textbox to a data base. I have a Window forms with 6 textbox fields and a button click event that will save the input from these 6 textbox fields to my table called User profile that has 7 columns name Fname, Lname, UserName, Email, Pword, RePword, UserNumber. I have not been able to successfully do this the other tutorials i have found on this does not have this problem. I have not added any validation to this becuase i just wanted to get it working before i started adding validation and other things.. to it.. Here is my currect code..
SqlConnection CnNew = new SqlConnection();
CnNew.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Program Files\Microsoft Visual Studio 9.0\VC#\CSharpProjects\MyDiaryVersionOne\MyDiaryVersionOne\MyDiary.mdf;Integrated Security=True;User Instance=True";
SqlCommand CmdSql = new SqlCommand();
string query = "INSERT INTO UserProfile VALUES(Fname,Lname,UserName,Email,Pword,RePword,UserNumber)";
CmdSql.CommandText = query;
CmdSql.CommandType = CommandType.Text;
CmdSql.Parameters.AddWithValue("Fname", TxtbxFname.Text);
CmdSql.Parameters.AddWithValue("Lname", TxtbxLname.Text);
CmdSql.Parameters.AddWithValue("UserName", TxtbxUname.Text);
CmdSql.Parameters.AddWithValue("Email", TxtbxEmail.Text);
CmdSql.Parameters.AddWithValue("Pword", TxtbxPword.Text);
CmdSql.Parameters.AddWithValue("RePword", TxtbxRepword.Text);
CmdSql.Parameters.AddWithValue("UserNumber", TxtbxUname.Text);
CmdSql.Connection = CnNew;
CnNew.Open();
CmdSql.ExecuteNonQuery();
<Will The Great>