INSERT查询显示插入的数据,但实际上没有插入数据

时间:2012-09-24 01:37:09

标签: c# sql-server query-parameters

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

1 个答案:

答案 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);