如何将存储过程值显示到datagridview

时间:2018-10-06 20:59:21

标签: c# sql-server

我有以下存储过程:

CREATE PROCEDURE abc
AS
    SELECT CustomerID 
    FROM Customers 
    WHERE CustomerID < 10

    SELECT GuarantorID 
    FROM Guarantors 
    WHERE GuarantorID < 10

我的datagridview中有两列。我想在第一列中显示CustomerID,在第二列中显示GuarantorID

我的C#代码在datagridview上没有显示任何值

using (SqlConnection conn = new SqlConnection(connection))
{
    using (SqlCommand cmd = new SqlCommand("dbo.abc", conn))
    {
        SqlDataAdapter sda = new SqlDataAdapter("abc",conn);

        sda.SelectCommand.CommandType = CommandType.StoredProcedure;

        DataTable dt = new DataTable();
        sda.Fill(dt);

        dataGridView1.DataSource = dt.DefaultView;                      
    }        
}

0 个答案:

没有答案