Hi,
I would like to extract data from an MySQL database table in my Software (on the fly). I have found the following example of how to add data to a table in Software and it works fine.
// specify the data source
string connContStr = ConfigurationManager.ConnectionStrings["my_connection1"].ConnectionString;
SqlConnection myContConn = new SqlConnection(connContStr);
// define the command query
String myContQuery = "INSERT INTO ContactUs (contType, contName, contEmail, contTel, contMessage, contDate) VALUES (@contType, @contName, @contEmail, @contTel, @contMessage, @contDate)";
SqlCommand myContCommand = new SqlCommand(myContQuery, myContConn);
myContCommand.Parameters.Add(new SqlParameter("@contType", dropdownType.Text));
myContCommand.Parameters.Add(new SqlParameter("@contName", txtName.Text));
myContCommand.Parameters.Add(new SqlParameter("@contEmail", txtEmail.Text));
myContCommand.Parameters.Add(new SqlParameter("@contTel", txtTel.Text));
myContCommand.Parameters.Add(new SqlParameter("@contMessage", txtMessage.Text));
myContCommand.Parameters.Add(new SqlParameter("@contDate", DateTime.Now));
myContConn.Open();
myContCommand.ExecuteNonQuery();
myContConn.Close();
Can anyone point me to an example of how to extract data in a similar fashion? (I know that the "INSERT INTO..." should change to something like "SELECT [contName], [contEmail] FROM [ContactUs]".
Also, how will the syntax look to display the information from say "contName" in a Label?
Label.Text = ??
Thanks for your feedback.
Regards
Jan