我在做一个数据库的查询时,用DataGrid显示查询数据库的结果,代码是这样的:
        sqlSelectCommand1.CommandText = "SELECT 点名, X坐标, Y坐标, [2002], [1998], [2000], [1999], [1994], [1988], 备注 FROM SecondLevelResult WHERE (点名 = @dmtxt)";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@dmtxt", System.Data.SqlDbType.NVarChar, 255, "点名"));
         string vdmtxt;
         vdmtxt=dmtxt.Text;
sqlDataAdapter1.SelectCommand.Parameters["@dmtxt"].Value = vdmtxt;
sqlDataAdapter1.Fill(myDataSet1);
if (!IsPostBack)
{
DataGrid1.DataBind();

}可是运行时,在文本框中输入点名查询时提示说:数据集中没有数据。
请教各位高手:什么原因导致这个错误?

解决方案 »

  1.   


    if (!IsPostBack)
    {
    sqlSelectCommand1.CommandText = "SELECT 点名, X坐标, Y坐标, [2002], [1998], [2000], [1999], [1994], [1988], 备注 FROM SecondLevelResult WHERE (点名 = @dmtxt)";
    this.sqlSelectCommand1.Connection = this.sqlConnection1;
    this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@dmtxt", System.Data.SqlDbType.NVarChar, 255, "点名"));
             string vdmtxt;
             vdmtxt=dmtxt.Text;
    sqlDataAdapter1.SelectCommand.Parameters["@dmtxt"].Value = vdmtxt;
    sqlDataAdapter1.Fill(myDataSet1);
    DataGrid1.datasource=myDataSet1;
    DataGrid1.DataBind();

    }
      

  2.   

    DataGrid1.datasource=myDataSet1.tables(0)
      

  3.   

    http://blog.csdn.net/zhzuo/archive/2004/08/06/67016.aspx
      

  4.   

    同意没有设定datagrid1的datasource