我有一个Windows表单,它将永远将数据加载到我的datagridview中.
我一直在这行中得到错误:
dataGridView1.Rows.Add(row);
Run Code Online (Sandbox Code Playgroud)
跨线程操作无效:控制'dataGridView1'从其创建的线程以外的线程访问.
这是我的代码:
public List<string> _checked = new List<string>();
private void getBarcodProperty()
{
string query = "select Name from RfidUnic where Barcode = @barcode";
while (true)
{
while (_checked.Count > 0)
{
SQLiteCommand cmd = new SQLiteCommand(query, sqliteConnection);
cmd.Parameters.AddWithValue("@barcode", _checked[0]);
sqliteConnection.Open();
SQLiteDataReader da = cmd.ExecuteReader();
if (da.Read())
{
if (!da.IsDBNull(0))
{
string[] row = new string[] { da[0].ToString(), "1", _checked[0] };
dataGridView1.Rows.Add(row);
_checked.RemoveAt(0);
}
}
else
{
string[] row = new string[] { "empty", "1", _checked[0] };
dataGridView1.Rows.Add(row); …Run Code Online (Sandbox Code Playgroud)