c# 中数据库查询问题(判断为空)
以下是代码:stringstrConn="server=.;database=mydb;uid=sa;pwd=sa";SqlConnectionmyConnection=...
以下是代码:
string strConn = "server=.;database=mydb;uid=sa;pwd=sa";
SqlConnection myConnection = new SqlConnection(strConn);
myConnection.Open();
DataSet myDataset = new DataSet();
string i = this.TextBox1.Text;
string sqlText = "select *from person where id="+i;
SqlDataAdapter myDataAdapter = new SqlDataAdapter(sqlText, myConnection);
myDataAdapter.Fill(myDataset);
///想在这里加个判断,查询内容不未空是才显示到grieview中
this.GridView1.DataSource = myDataset;
this.GridView1.DataBind(); 展开
string strConn = "server=.;database=mydb;uid=sa;pwd=sa";
SqlConnection myConnection = new SqlConnection(strConn);
myConnection.Open();
DataSet myDataset = new DataSet();
string i = this.TextBox1.Text;
string sqlText = "select *from person where id="+i;
SqlDataAdapter myDataAdapter = new SqlDataAdapter(sqlText, myConnection);
myDataAdapter.Fill(myDataset);
///想在这里加个判断,查询内容不未空是才显示到grieview中
this.GridView1.DataSource = myDataset;
this.GridView1.DataBind(); 展开
展开全部
string strConn = "server=.;database=mydb;uid=sa;pwd=sa";
SqlConnection myConnection = new SqlConnection(strConn);
myConnection.Open();
DataTable dt= new DataTable();
string i = this.TextBox1.Text;
string sqlText = "select *from person where id="+i;
SqlDataAdapter myDataAdapter = new SqlDataAdapter(sqlText, myConnection);
myDataAdapter.Fill(dt);
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
if(dt.rows.count<=0)
{
//提示消息,数据不存在。
}
SqlConnection myConnection = new SqlConnection(strConn);
myConnection.Open();
DataTable dt= new DataTable();
string i = this.TextBox1.Text;
string sqlText = "select *from person where id="+i;
SqlDataAdapter myDataAdapter = new SqlDataAdapter(sqlText, myConnection);
myDataAdapter.Fill(dt);
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
if(dt.rows.count<=0)
{
//提示消息,数据不存在。
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
if(myDataset.Tables[0].Rows.Count == 0){ //这个myDataset为空}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询