我想通过gridview列名将数据库中的特定行添加到gridview。请发给我代码。或者帮助我编写代码。 dgvSale
try
{
string sql = "SELECT * FROM PackageProduct where IDs='" + id + "'";
SqlCommand Comm11 = new SqlCommand(sql, con);
con.Open();
SqlDataReader DR11 = Comm11.ExecuteReader();
while (DR11.Read())
{
dgvSale.Cells[1].Value = DR11["ProductName"].ToString().Trim();
dgvSale.Cells[2].Value = DR11["ProductQty"].ToString().Trim();
dgvSale.Cells[3].Value = DR11["Price"].ToString().Trim();
dgvSale.Cells[4].Value = DR11["Discount"].ToString().Trim();
dgvSale.Cells[5].Value = DR11["TotalAmount"].ToString().Trim();
}
con.Close();
}
catch (Exception ex)
{
XtraMessageBox.Show("Error" + ex.Message);
con.Close();
}
答案 0 :(得分:0)
试试这个
DataTable table = new DataTable();
table.Load(DR11);
dgvSale.DataSource = table;
reader.Close();