Display MySQL Data in a Label - Vb.Net
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开发者_StackOverflow社区 display that phone number on a label?
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:
VBMySQL Tutorial - Part 4
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
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();
}
}
}
精彩评论