我們在數據庫中創建了一個存儲過程。它工作得很好,但我無法弄清楚如何在我的代碼中調用它。出於某種原因,我不斷收到回在C#中存儲過程(ASP.NET CORE)
過程或函數「GetNextApplicationNumber」需要參數「@ApplicationId」,但未提供。
我的代碼:
string connectionString = "THE_CONNECTION_STRING";
using (IDbConnection connection = new SqlConnection(connectionString))
using (IDbCommand command = connection.CreateCommand())
{
command.CommandType = CommandType.StoredProcedure;
IDbDataParameter parameter = command.CreateParameter();
parameter.ParameterName = "@ApplicationId";
parameter.Value = applicationId;
parameter.DbType = DbType.String;
command.Parameters.Add(parameter);
command.CommandText = "[dbo].[GetNextApplicationNumber]";
connection.Open();
using (IDataReader reader = command.ExecuteReader())
{
string applicationNumber = string.Empty;
if (reader.Read())
{
applicationNumber = reader.GetValue(0).ToString();
}
return applicationNumber;
}
}
我已經嘗試了不少不同的方式(其中大部分似乎已經過時,不再可用)。
您可以嘗試使用SQL Server Profiler來analize的SQL發送到您的SQL Server。儘量不要設置參數的DbType屬性。 – musium