[英]how to show specific rows from database on gridview in C#
I want to add specific rows from database to gridview by gridview column name.我想通过 gridview 列名将特定行从数据库添加到 gridview。 Please send me code for this.请给我发送代码。 Or help me in my code.或者在我的代码中帮助我。 dgvSale 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();
}
try this尝试这个
DataTable table = new DataTable();
table.Load(DR11);
dgvSale.DataSource = table;
reader.Close();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.