Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 一个参数值按字面意思更新,但其他参数值在C语言中运行良好#_C#_Sql Server_Gridview - Fatal编程技术网

C# 一个参数值按字面意思更新,但其他参数值在C语言中运行良好#

C# 一个参数值按字面意思更新,但其他参数值在C语言中运行良好#,c#,sql-server,gridview,C#,Sql Server,Gridview,我正在处理insert语句,其中需要插入3个值,从gridview获取数据并将其保存在表中,但“关键字参数值正在按字面意思更新,就像数据库中的@Keyword”,但其他值正在变好 下面是代码 using (SqlCommand com = new SqlCommand("INSERT INTO PositionsTable (Id,Keyword,Position) VALUES (@Id,'@Keyword',@Position)", con))

我正在处理insert语句,其中需要插入3个值,从gridview获取数据并将其保存在表中,但“关键字参数值正在按字面意思更新,就像数据库中的@Keyword”,但其他值正在变好

下面是代码

            using (SqlCommand com = new SqlCommand("INSERT INTO PositionsTable (Id,Keyword,Position) VALUES (@Id,'@Keyword',@Position)", con))
            {
                com.Parameters.AddWithValue("@Keyword", SqlDbType.VarChar);
                com.Parameters.AddWithValue("@Position", SqlDbType.Int);
                com.Parameters.AddWithValue("@Id", SqlDbType.Int);

                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    string keywordCell = dataGridView1.Rows[i].Cells["Keywords"].Value.ToString();
                    int positionCell = Convert.ToInt16(dataGridView1.Rows[i].Cells["Position"].Value);

                    com.Parameters["@Keyword"].Value = keywordCell;
                    com.Parameters["@Position"].Value = positionCell;
                    com.Parameters["@Id"].Value = count;
                    com.ExecuteNonQuery();
                }
            }
使用(SqlCommand com=newsqlcommand(“插入到位置稳定(Id,关键字,位置)值(@Id,@Keyword,@Position)”,con))
{
com.Parameters.AddWithValue(“@关键字”,SqlDbType.VarChar);
com.Parameters.AddWithValue(“@Position”,SqlDbType.Int);
com.Parameters.AddWithValue(“@Id”,SqlDbType.Int);
对于(int i=0;i
我在调试时测试了keywordCell变量,它成功地从gridview获得了值,就像positionCell一样,但它在positionCell正确更新的数据库中得到了更新“@Keyword”


你能指出我哪里出错了吗?

你在SQL语句中引用了round关键字

改变

"INSERT INTO PositionsTable (Id,Keyword,Position) VALUES (@Id,'@Keyword',@Position)"


在SQL语句中有引号round关键字

改变

"INSERT INTO PositionsTable (Id,Keyword,Position) VALUES (@Id,'@Keyword',@Position)"


值(…)中的“@Keyword”
是错误的

INSERT INTO PositionsTable (Id,Keyword,Position) VALUES (@Id, @Keyword, @Position)" 

值(…)中的“@Keyword”是错误的

INSERT INTO PositionsTable (Id,Keyword,Position) VALUES (@Id, @Keyword, @Position)" 

@我将很快接受答案不能取悦我漏掉了那一个:(@将很快接受答案不能取悦我漏掉了那一个:(