110,534
社区成员
发帖
与我相关
我的任务
分享
//sql语句就有问题
string strSql = "";
strSql = "select Count(stuNum) from preInfo "; //注意了
SqlConnection conn = new SqlConnection("server=.;database=RoomclassLayout;uid=sa;pwd=000000");
conn.Open();
SqlCommand comm = new SqlCommand(strSql, conn);
int mystuNum = Convert.ToInt32(comm.ExecuteScalar()); //注意了
if(mystuNum>0)
{
MessageBox.Show("这条数据存在!");
}
else
{
MessageBox.Show("这条数据不存在存在!");
}
string name = Request.QueryString["name"];
string sql = string.Format("select name from Users where name='{0}'", name);
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=Student;User ID=sa;password=123");
conn.Open();
SqlCommand command = new SqlCommand(sql,conn);
SqlDataReader reader = command.ExecuteReader();
try
{
if (reader.Read())
{
Response.Write("ok");//存在
}
}
catch (Exception)
{
Response.Write("fail");//不存在
}
finally {
conn.Close();
}