protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text != "")
{
string strConnection = "server=.;database=colorring;uid=sa;pwd=";
string strSql = "select top 1 ringid from s50usersysringgrp where ringid=@ringid";
SqlConnection con = new SqlConnection(strConnection);
SqlCommand com = new SqlCommand(strSql, con);
con.Open();
com.Parameters.Add("@ringid", SqlDbType.Char, 12).Value = TextBox1.Text;
SqlDataReader dr = com.ExecuteReader();
if (dr.Read())
{
TextBox2.Text = "数据库中有该ringid";
}
else
{
TextBox2.Text = "数据库中没有该ringid";
}
dr.Close();
con.Close();
}
else
{
TextBox2.Text = "你没有输入任何值";
}
}
本文介绍了一个使用C#实现的简单数据库查询示例。通过用户输入的RingID查询数据库s50usersysringgrp表中是否存在相应的记录。若存在则返回查询结果,否则提示未找到相关信息。
601

被折叠的 条评论
为什么被折叠?



