asp.net插入记录问题

来源:百度知道 编辑:UC知道 时间:2024/06/13 23:31:02
SqlCommand cmd_4 = new SqlCommand("insert into mynews values ('this is a new title!') SELECT @@IDENTITY as 'bh'", con)

mynews表中有 id ,title,newsCount,连接数据库没问题,就是执行到这段,说插入错误,参数不对,不知道怎么改,各位帮看看
SELECT @@IDENTITY as 'bh'这句能解释一下吗

SqlCommand cmd_4 = new SqlCommand("insert into mynews(title) values ('this is a new title!') SELECT @@IDENTITY as 'bh'", con)

如果你插入的参数个数和表的列数不一致的话, 需要在表名后面指名插入哪个列

你的插入数据语据不正确呀.
语法为:insert into tablename (itemname) values (value)

mynews表中有 id ,title,newsCount 有这三个字段,还有,你看一下,数据库中是否有不允许为空的字段.
insert into mynews(id,title,newsCount)Values(对应的ID,对应的title,对应的newsCount) 这样才正确的.

我记得语法是insert into tablename (itemname) values (value)