我将提供项目的条形码,然后项目数据将被提取到datagridview。
这些代码只获取一行,如果再次填充条形码此代码更新行不更新新行。我想要新行
SqlConnection con = new SqlConnection("Data Source=(local);Initial Catalog=QuickBook;Integrated Security=True");
string query = "select productName,productDescription,productUnitPrice from productsInfo where productBarcode =" + p_barcode.Text + "";
SqlCommand cmd = new SqlCommand(query, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
con.Open();
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
答案 0 :(得分:0)
尝试用'撇号
进行检查string query = "select productName,productDescription,productUnitPrice from productsInfo where productBarcode = '" + p_barcode.Text + "'";
答案 1 :(得分:0)
da.Fill(dt);
//this loop is pseudocode. Dont remember the exakt syntax
Foreach(DataRow r in dt)
{
dgvDT. Rows. Add(r. Copy())
}
dataGridView1.DataSource = dgvDT;
使dgvDT成为数据库而非局部变量