sql语句查询与textbox相符的结果,显示在datagridview中。
  如果没有相符的,datagridview显示空记录,弹出提示没有找到相符的,这个代码如何写呢?

解决方案 »

  1.   

    <emptydatetemplte>里边写,没有数据时会自动显示的
      

  2.   

    我的是c/s 窗体的,没有<emptydatetemplte>啊,是如果没有符合条件的提示
      

  3.   

    string selectstr = String.Format("SELECT * FROM Table WHERE Field = '{0}'",this.TextBox1.Text);
    string ConnectionString = "你的连库字符串";
    SqlConnection myconn = new SqlConnection();
                myconn.ConnectionString = ConnectionString;
                myconn.Open();
                SqlDataAdapter myda = new SqlDataAdapter();
                myda.SelectCommand = new SqlCommand(selectstr, myconn);
                DataSet ds = new DataSet();
                myda.Fill(ds);
                myconn.Close();
    if (ds.Tables[0].Rows.Count > 0)
    {
        //有数据
    }
    else
    {
        //无
    }
      

  4.   

    //有数据
    重新绑定datagridview
    //无
    清空datagridview
    并且MessageBox.Show("没有数据");
      

  5.   

    把查询出来的是数据放入一个DataSet,然后和TextBox能文本对比,筛选出数据放如另一个DataSet,判断是否为空即可.
      

  6.   

    if(ds.Rows.Count > 0 )
    { this.dataGridView1.DataSource = ds.Tables[0];
    else
    {MessageBox.Show("没有找到符合的记录");}
      

  7.   

    if(ds.Tables["..."].Rows.Count==0)
    {

    }
    else
    {
    } }
      

  8.   

    if (ds.Tables[0].Rows . Count > 0)
                    { this.dataGridView1.DataSource = ds.Tables[0]; }
                    else
                    { MessageBox.Show("没有找到符合的记录"); }
                                }正解,谢谢!