我从数据库中选择一行。我想将该行添加到datagridview,该行在该行中有3列。我想将这3列添加到3行。任何人都可以提供帮助吗?谢谢!
这是我的查询
fillGrid("select selPriceCash1 as [Price 01] ,selPriceCash2 as [Price 02] ,selPriceCash3 as [Price 03] from tblItemInfo where code='" + itCode + "'");
我的代码
private void fillGrid(string selectCmd)
{
try
{
BindingSource b = new BindingSource();
DataTable dt = cMethos.selectAtable(selectCmd);
b.DataSource = dt;
dgSend.DataSource = dt;
if (dt.Rows.Count < 0)
{
dgSend.Rows[0].Cells[0].Selected = true;
}
}
catch (Exception es)
{
MessageBox.Show(es.Message);
}
}
答案 0 :(得分:0)
不是最漂亮但应该有效
private void fillGrid(string selectCmd)
{
List<string> Results = new List<string>();
DataTable dt = cMethos.selectAtable(selectCmd);
foreach(DataRow row in dt.Rows())
{
foreach (object rowObject in row.ItemArray)
{
Results.Add(rowObject.ToString());
}
}
dgSend.DataSource = Results;
}