SQL Server参数"未提供" - 但它是

时间:2014-03-11 19:19:41

标签: c# sql sql-server ado.net

考虑这段代码...... 为什么没有告诉我在尝试执行存储过程时没有设置@PI_CDID参数值?

Console.WriteLine("Database Opened!");
SqlCommand cmd = new SqlCommand("P_IOU_Track", conn);
cmd.Parameters.Add(new SqlParameter("@PI_CDID", ICDID)); // parameter is added here
cmd.Parameters.Add(new SqlParameter("@PI_Title", ITitle));
cmd.Parameters.Add(new SqlParameter("@PI_Duration", IDuration));
cmd.Parameters.Add(new SqlParameter("@PI_CDNo", ICDNo));
cmd.Parameters.Add(new SqlParameter("@PI_TNo", ITNo));
foreach (SqlParameter p in cmd.Parameters )
{
    Console.WriteLine("Parameter , {0} , Value --> {1} ",p.ParameterName, p.Value.ToString());
}
// Add output param
SqlParameter NextTID = new SqlParameter("@PO_NextTID", SqlDbType.BigInt);
NextTID.Direction = ParameterDirection.Output;
cmd.Parameters.Add(NextTID);
// Execute procedure
cmd.ExecuteNonQuery();

1 个答案:

答案 0 :(得分:1)

您忘记了cmd.CommandType = CommandType.StoredProcedure