C# 一个参数值按字面意思更新,但其他参数值在C语言中运行良好#
我正在处理insert语句,其中需要插入3个值,从gridview获取数据并将其保存在表中,但“关键字参数值正在按字面意思更新,就像数据库中的@Keyword”,但其他值正在变好 下面是代码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))
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)"
@我将很快接受答案不能取悦我漏掉了那一个:(@将很快接受答案不能取悦我漏掉了那一个:(