如何从.net调用此存储过程?

时间:2018-02-09 17:46:59

标签: c# sql-server

我尝试从数据库中获取exp的列接收器数为x的行数。

存储过程定义:

alter procedure [dbo].[lattercountin] 
    (@receiver NVarchar(150)) 
as 
begin 
    select count(idlatter) as cnt 
    from sendlatter 
    where receiver = @receiver 
end

这是C#代码:

string prc = "lattercountin";

SqlCommand cmd = Phone_Book.getEntries(prc);

cmd.Parameters.Add("@receiver", SqlDbType.NVarChar);

try
{
    cmd.Parameters["@receiver"].Value = Entry.receiver;

    SqlDataAdapter data = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable();
    data.Fill(dt);

    Entry.sender = (string)dt.Rows[0][0];
}
finally
{
    if (connection.State != ConnectionState.Closed)
        connection.Close();
}

这是错误:

** OP您的错误在哪里**

0 个答案:

没有答案