错误 System.ArgumentException:"Keyword not supported: "字符集“。”
Error System.ArgumentException: "Keyword not supported: "charset"."
我正在尝试使用 dataGridView 将一些数据插入我的数据库并填充它的单元格,但我收到以下错误 System.ArgumentException: "Keyword not supported: "charset"."
这是我的代码:
public string connect = "Server=localhost;Database=hardlight;Uid=root;pwd=platon6993;charset=utf8";
string StrQuery;
using (SqlConnection conn = new SqlConnection(connect))
{
using (SqlCommand comm = new SqlCommand())
{
comm.Connection = conn;
conn.Open();
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
StrQuery = @"INSERT INTO rabota VALUES ("
+ dataGridView1.Rows[i].Cells["id"].Value + ", "
+ dataGridView1.Rows[i].Cells["name"].Value + ", "
+ dataGridView1.Rows[i].Cells["dadada"].Value + ");";
comm.CommandText = StrQuery;
comm.ExecuteNonQuery();
}
}
}
我能做什么?请帮助
删除字符集,你的连接字符串应该是这样的
public string connect = "Server=localhost;Database=hardlight;Uid=root;Pwd=platon6993;";
您的查询字符串应包含 ' ' 作为字符串值
StrQuery = $"INSERT INTO rabota VALUES ( {dataGridView1.Rows[i].Cells["id"].Value},'{dataGridView1.Rows[i].Cells["name"].Value}', '{dataGridView1.Rows[i].Cells["dadada"].Value}')";
我正在尝试使用 dataGridView 将一些数据插入我的数据库并填充它的单元格,但我收到以下错误 System.ArgumentException: "Keyword not supported: "charset"."
这是我的代码:
public string connect = "Server=localhost;Database=hardlight;Uid=root;pwd=platon6993;charset=utf8";
string StrQuery;
using (SqlConnection conn = new SqlConnection(connect))
{
using (SqlCommand comm = new SqlCommand())
{
comm.Connection = conn;
conn.Open();
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
StrQuery = @"INSERT INTO rabota VALUES ("
+ dataGridView1.Rows[i].Cells["id"].Value + ", "
+ dataGridView1.Rows[i].Cells["name"].Value + ", "
+ dataGridView1.Rows[i].Cells["dadada"].Value + ");";
comm.CommandText = StrQuery;
comm.ExecuteNonQuery();
}
}
}
我能做什么?请帮助
删除字符集,你的连接字符串应该是这样的
public string connect = "Server=localhost;Database=hardlight;Uid=root;Pwd=platon6993;";
您的查询字符串应包含 ' ' 作为字符串值
StrQuery = $"INSERT INTO rabota VALUES ( {dataGridView1.Rows[i].Cells["id"].Value},'{dataGridView1.Rows[i].Cells["name"].Value}', '{dataGridView1.Rows[i].Cells["dadada"].Value}')";