我运行参数化INSERT
查询,它返回1(插入1行)。但是当我在SSMSE中查看表格时,我什么也看不见。下面代码中的return语句返回1.
以下是代码:
SqlCommand insertProject=new SqlCommand("Insert into tbl_project (id, project_name, project_desc, creator_user_id) VALUES('@id', '@project_name', '@project_desc', @creator_user_id)", conn);
insertProject.Parameters.AddWithValue("@id", id);
insertProject.Parameters.AddWithValue("@project_name", project_name);
insertProject.Parameters.AddWithValue("@project_desc", project_desc);
insertProject.Parameters.AddWithValue("@creator_user_id", creator_user_id);
return insertProject.ExecuteNonQuery();
答案 0 :(得分:2)
参数名称绝不能用单引号括起来。
SqlCommand insertProject = new SqlCommand("Insert into tbl_project
(id,project_name,project_desc,creator_user_id)
VALUES(@id,@project_name,@project_desc,@creator_user_id)",conn);