我这里有一些连接到我的Mysql数据库的代码。它会检查您的用户名和密码,如果您的登录成功,它会检索该帐户下的电话号码。一旦连接,检索电话号码的SQL查询怎么样?那么我怎样才能在标签上显示该电话号码?
答案 0 :(得分:2)
答案 1 :(得分:1)
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();
}
}
}