2

我运行参数化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();
4

1 回答 1

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);
于 2012-09-24T01:38:40.383 回答