Ah yes ... he didn't really answer your original question explicitly, did
he? Although he gave you enough to put it together pretty easily.
Here's his insert:
cmd.CommandText= "insert into fred (a,b) values (1,'a')";
Now, if you want to put the value of a textbox into field b in his example,
you would replace the value 'a' with the textbox value. That would be the
Text property of the textbox, so if the texbox were named myTextBox, you'd
have:
cmd.CommandText = String.Format("insert into fred (a,b)
values(1,'{0}')",myTextBox.Text);
Of course this is static SQL which is inefficient and sets you up for SQL
injection attacks and would also blow up if for example the user happened to
type an apostrophe into the textbox, so what you would really want to do is
a parameterized query. So his original code would be something like this:
System.Data.SqlClient.SqlConnection cn = new
System.Data.SqlClient.SqlConnection(....);
cn.Open();;
System.Data.SqlClient.SqlCommand cmd=new
System.Data.SqlClient.SqlCommand(cn);
cmd.CommandText= "insert into fred (a,b) values (@a,@b)";
cmd.Parameters.Add("@a",SqlDbType.Int).Value = 1;
cmd.Parameters.Add("@b",SqlDbType.Varchar,20).Value = myTextBox.Text;
cmd.ExecuteNonQuery();
cn.Close();
Ignoring, of course, validation in the textbox, error handling, the exact
schema of your database, etc. But this should give you the basic direction.
--Bob