0

我绑定了我的gridview( dgvresult2) 从存储过程中读取数据。当我调试我的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;
    }
}
4

0 回答 0