.Net Newb Needs Help

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();
}
 
B

Bill

Thanks for your response Dave. Boy I feel dumb! I was entering the
input from the last name field into the email address field. So
obviously, when I searched the db for the email address I entered in
the form it never returned a record.

cmd.Parameters.Add("@myEmail", SqlDbType.NVarChar, 50).Value =
users_last_name.Text;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top