Reputation: 6448
I have some code here that connects to my Mysql database. It checks your username and password and if your login was successful and it retrieves the phone number under that account. How would the SQL Query look like for retrieving the phone number once connected? Then how would I be able to display that phone number on a label?
Upvotes: 0
Views: 3238
Reputation: 3745
public partial class _Default : System.Web.UI.Page {
string strCon = ConfigurationManager.AppSettings["myConString"];
SqlConnection con;
SqlCommand com;
public string strPKDataValue;
public SqlDataReader dr;
protected void Page_Load(object sender, EventArgs e)
{
con = new SqlConnection(strCon);
}
protected void Button5_Click(object sender, EventArgs e) { com = new SqlCommand("select * from student", con); con.Open();
try
{
dr = com.ExecuteReader(CommandBehavior.CloseConnection);
if (dr.HasRows)
{
if (dr.Read())
{
Label9.Text = Convert.ToString(dr["stuid"]);
}
}
}
catch (Exception ex)
{
Response.Write("Error :" + ex.Message);
}
finally
{
dr.Close();
con.Close();
}
}
}
Upvotes: 1
Reputation: 936
Have a look at this tutorial, should cover most of what you would need to know about connecting to MySQL, executing queries and displaying results:
There are a number of other tutorials on that site, should get you going.
If part 4 gets into too much depth too quickly, check out part 1 first
Upvotes: 2