B
Bill
I am trying for the first time to do a record insert into an mssql
database. I have not been successful in using parameters. When I
execute the code below, it should take the input from the form and
enter it into the database. I do not recieve an error but nothing is
entered into the database. If I directly enter the values into my
SqlCommand then the database inserts the record. Can someone please
look at my code below and tell me what I might be missing? How I can
properly test the parameters are being assigned correctly? Thanks so
much!
Bill
public void UpdateRows()
{
String myGeo1 = geo.SelectedValue.ToString();
SqlConnection conn = new SqlConnection("Data
Source=MYPC;Initial Catalog=tblRecords;Persist Security Info=True;User
ID=sa;Password=MYPASSWORD");
SqlCommand cmd = new SqlCommand("INSERT INTO tblResourceInfo
(strLastName, strFirstName, strEmail, Geo) Values (@myLname, @myFname,
@myEmail, @myGeo)", conn);
cmd.Parameters.Add("@myLname", SqlDbType.NVarChar, 40).Value =
users_last_name.Text;
cmd.Parameters.Add("@myFname", SqlDbType.NVarChar, 30).Value =
users_first_name.Text;
cmd.Parameters.Add("@myEmail", SqlDbType.NVarChar, 50).Value =
users_last_name.Text;
cmd.Parameters.Add("@myGeo", SqlDbType.Int).Value =
Convert.ToInt32(myGeo1);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
database. I have not been successful in using parameters. When I
execute the code below, it should take the input from the form and
enter it into the database. I do not recieve an error but nothing is
entered into the database. If I directly enter the values into my
SqlCommand then the database inserts the record. Can someone please
look at my code below and tell me what I might be missing? How I can
properly test the parameters are being assigned correctly? Thanks so
much!
Bill
public void UpdateRows()
{
String myGeo1 = geo.SelectedValue.ToString();
SqlConnection conn = new SqlConnection("Data
Source=MYPC;Initial Catalog=tblRecords;Persist Security Info=True;User
ID=sa;Password=MYPASSWORD");
SqlCommand cmd = new SqlCommand("INSERT INTO tblResourceInfo
(strLastName, strFirstName, strEmail, Geo) Values (@myLname, @myFname,
@myEmail, @myGeo)", conn);
cmd.Parameters.Add("@myLname", SqlDbType.NVarChar, 40).Value =
users_last_name.Text;
cmd.Parameters.Add("@myFname", SqlDbType.NVarChar, 30).Value =
users_first_name.Text;
cmd.Parameters.Add("@myEmail", SqlDbType.NVarChar, 50).Value =
users_last_name.Text;
cmd.Parameters.Add("@myGeo", SqlDbType.Int).Value =
Convert.ToInt32(myGeo1);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}