大家帮我看看为什么啊
public bool Insert(News n)
{
bool flag = false;
string proName = "procInsert";
//string proName = "insert into T_News(Title,CatId,Content) values(@Title,@CatId,@Content)";
SqlParameter[] paras = new SqlParameter[] {
new SqlParameter("@Title",n.Title),
new SqlParameter("@CatId",n.Catid),
new SqlParameter("@Content",n.Content)
};
int reg = sqlhelper.ExcuteNonQuery(proName, paras, CommandType.Text);
if (reg > 0)
{
flag = true;
}
return flag;
}
存储过程:ALTER PROCEDURE procInsert
/*
(
@parameter1 int = 5,
@parameter2 datatype OUTPUT
)
*/
@Title varchar(50),
@CatId int,
@Content text
AS
insert into T_News(Title,CatId,Content) values(@Title,@CatId,@Content)
return
exec procInsert
如果我换成SQL语句就可以,用存储过程就不行了
------解决方案--------------------------------------------------------
- C# code
SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@Title",sqldbtype.VarChar), new SqlParameter("@CatId",sqldbtype.Int), new SqlParameter("@Content",sqldbtype.VarChar)}paras[0].direction = parameterdirection.input;paras[0].value =n.Title;paras[1].direction = parameterdirection.input;paras[1].value =n.Catid;paras[2].direction = parameterdirection.input;paras[2].value =n.Content;
------解决方案--------------------------------------------------------
LZ,你都没传数据给title,还有楼主最好别直接给参数,最好在sqlpar那个里面先定义,然后par.vales[1]="参数",这样执行速度比你那样写要快10倍,大数据量你就知道了