从存储过程绑定Gridview

时间:2013-10-09 09:59:15

标签: asp.net stored-procedures datagrid webforms

我从存储过程中绑定了我的gridviewdgvresult2)读取数据。当我调试gridview.rows.count时,虽然我的DataSet表有5行(ds.Tables[0].Rows.Count),但它为零。

请帮忙解决这个问题 - 以下是我的代码:

private void ReturnResult ( )
{
        try
        {
            string connetionString = null;
            lblcino.Text = "1234";

        connetionString = "Data Source= SLB-84NKBT1\\SQLEXPRESS;Initial Catalog=WireLine Tracking Assets; User=admin; pwd=password123";
        SqlConnection connection = new SqlConnection(connetionString);

        connection.Open();
        SqlCommand command = new SqlCommand("GetCIno", connection);
        command.CommandType = CommandType.StoredProcedure;
        command.Parameters.Add("@CustomerInvoiceNo", SqlDbType.NChar).Value = lblcino.Text; //((Label)dgvresult.FooterRow.FindControl("lblcino")).Text;

        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(command);
        da.Fill(ds);

        if (ds.Tables.Count > 0)
        {
            if (ds.Tables[0].Rows.Count > 0)
            {
                dgvresult2.DataSource = ds;
                dgvresult2.DataBind();
                dgvresult2.Visible = true;
            }
        }
        else
        {
            string message = "ds is Empty";
            ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup('" + message + "');", true);
        }
        connection.Close();
    }
    catch (Exception)
    {
        throw;
    }
}

0 个答案:

没有答案