我在SQL Server中添加了存储过程 - 代码如下所示:
CREATE PROCEDURE [dbo].[sp_insertinfo]
@model NVARCHAR(255),
@price INT,
@id INT
AS
INSERT INTO computers (model, price, id)
VALUES (@model, @price, @id)
SET @id = SCOPE_IDENTITY()
SELECT SCOPE_IDENTITY()
GO
CREATE PROCEDURE [dbo].[sp_getinfo]
AS
SELECT *
FROM computers
GO
之后我尝试在Visual Studio中使用它
using (SqlConnection con = new SqlConnection(ConnectionSTring))
{
con.Open();
SqlCommand cmd = new SqlCommand(SqlExpression,con);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
SqlParameter modelparam = new SqlParameter
{
ParameterName = "@model",
Value = model
};
SqlParameter priceparam = new SqlParameter
{
ParameterName = "@price",
Value = price
};
SqlParameter idparam = new SqlParameter
{
ParameterName = "@id",
Value = id
};
cmd.Parameters.Add(modelparam);
cmd.Parameters.Add(priceparam);
cmd.Parameters.Add(idparam);
int rid = cmd.ExecuteNonQuery();
我收到以下错误:
无法找到存储过程' sp_insertinfo'。
可能是什么问题?
答案 0 :(得分:0)
我将过程名称从sp_insertinfo更改为insert_info和sp_getinfo - > get_info,它工作正常