I’m learning basic c# using visual studio 2010 and I’m creating an application which uses a SQL server database.
The application will allow a user to enter text into a rich text box, press a button, and then show “stored” words in text box 2. These stored words are only words that being with *.
I have my database file but I can’t figure out how to do the code for it. So far I have,
SqlConnection myConn = new SqlConnection(@"Server=.\SQLEXPRESS;AttachDbFilename='C:\datafile.mdf';Integrated Security=True;User Instance=True");
con.Open();
SqlCommand com = new SqlCommand("SELECT name FROM bbc", con);
SqlDataReader sdr = com.ExecuteReader();
while (sdr.Read())
{
this.txtbox2.Text.Add(sdr[""]);
}
this is under my button handler.
I have my data file set up so it’s just the case of really how to set it to get data from text box 1 and show it in text box 2
I would use something like this:
It’s much more simple and usually more efficient to let SQL limit your query results.