C# Gridview选择下一页C的行#

C# Gridview选择下一页C的行#,c#,.net,gridview,C#,.net,Gridview,我需要在下一页中获取所选的Gridview行。。我在if(条件)处遇到异常,无法找到表0,因此下面是我的代码。请帮助我 protected void Page_Load(object sender, EventArgs e) { SqlConnection con = new SqlConnection(cs); String abc = "Select fname,lname,city,address,empid,email,phone,departme

我需要在下一页中获取所选的Gridview行。。我在if(条件)处遇到异常,无法找到表0,因此下面是我的代码。请帮助我

protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(cs);
        String abc = "Select fname,lname,city,address,empid,email,phone,department from employee Where id=" + Request.QueryString["a"];
        SqlCommand cmd = new SqlCommand(abc, con);
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = cmd;
        DataSet ds = new DataSet();
        **if (ds.Tables[0].Rows.Count > 0)**   //getting error at this
        {
            fname.Text = ds.Tables[0].Rows[0]["fname"].ToString();
            lname.Text = ds.Tables[0].Rows[0]["lname"].ToString();
            ddl1.SelectedItem.Value = ds.Tables[0].Rows[0]["city"].ToString();
            address.Text = ds.Tables[0].Rows[0]["address"].ToString();
            empid.Text = ds.Tables[0].Rows[0]["empid"].ToString();
            email.Text = ds.Tables[0].Rows[0]["email"].ToString();
            phone.Text = ds.Tables[0].Rows[0]["phone"].ToString();
            DropDownList1.SelectedItem.Value = ds.Tables[0].Rows[0]["department"].ToString();


        }
    }

在发生“line on”错误之前,您需要填充数据集

da.Fill(ds, "MyTable")
编辑:

你也没有打开你的连接

SqlConnection con = new SqlConnection(cs);
//Open the connection
con.Open()
String abc = "Select fname,lname,city,address,empid,email,phone,department from employee Where id=" + Request.QueryString["a"];
SqlCommand cmd = new SqlCommand(abc, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
//Fill the dataset
da.Fill(ds, "MyTable")
//Close the connection
con.Close()

...

我在dataapdater处得到了不正确的synatax=错误。。