I am new to programming and I am struggling with an sql select statement. I would really appreciate any help anyone can offer me!
What I am trying to do is populate a textbox (using code and without creating a dataset) with data retrieved from an sql database.
I have used the following code, but don't seem to be coming right:
String conn_String = "server=localhost;database=contacts_db;uid=sa;pwd=sqlsecret"; SqlConnection mySqlconn = new SqlConnection(conn_String); mySqlconn.Open(); String mySel_string = "SELECT firstName FROM contacts_tbl WHERE firstName = @fName"; SqlCommand mySqlcmd = new SqlCommand(mySel_string, mySqlconn); SqlParameter myfNameParam = mySqlcmd.Parameters.Add("@fName", SqlDbType.NVarChar,50); myfNameParam.Value = textBox1.Text; mySqlcmd.ExecuteNonQuery();
I would really appreciate any help!