C#怎样使 dataGridView1显示数据的时候,dataGridView1的列与数据库表里面的列一一对应?
发布网友
发布时间:2022-04-11 22:19
我来回答
共3个回答
热心网友
时间:2022-04-11 23:48
DataSet ds_sp = new DataSet();
DataTable dt_sp = new DataTable();
if (string.IsNullOrEmpty(strFilter))
{
strFilter = " 1=1";
}
dt_sp = DbHelper.getSqlTaskList(tablename, "*", sortExpr, this.SGVTask.PageSize, pageIndex, 0, strFilter, sortDirect);//Sql 中使用翻页函数
DataTable dtTask = dt_sp;
for (int i = 0; i < dtTask.Rows.Count; i++)
{
DataRow dr = dt.NewRow();
dr["YMD"] = dtTask.Rows[i]["YMD"].ToString();
dr["SDSHAN"] = dtTask.Rows[i]["SDSHAN"].ToString();
dr["ABALPH"] = dtTask.Rows[i]["ABALPH"].ToString();
dr["XSJE"] = dtTask.Rows[i]["XSJE"].ToString();
dr["FenTan_Month"] = dtTask.Rows[i]["FenTan_Month"].ToString();
dr["Cont_KeBian"] = dtTask.Rows[i]["Cont_KeBian"].ToString();
dr["Contract_Num"] = dtTask.Rows[i]["Contract_Num"].ToString();
dr["FenTan_Mode"] = dtTask.Rows[i]["FenTan_Mode"].ToString();
dr["FenTan_BL_Je"] = dtTask.Rows[i]["FenTan_BL_Je"].ToString();
dr["CJ"] = dtTask.Rows[i]["CJ"].ToString();
dr["FixSmOrderNum"] = dtTask.Rows[i]["FixSmOrderNum"].ToString();
dr["ftfs"] = dtTask.Rows[i]["ftfs"].ToString();
dr["FTDAI"] = dtTask.Rows[i]["FTDAI"].ToString();
dr["DAIKM"] = dtTask.Rows[i]["DAIKM"].ToString();
dr["FTJIE"] = dtTask.Rows[i]["FTJIE"].ToString();
dr["JIEKM"] = dtTask.Rows[i]["JIEKM"].ToString();
dr["MEMO"] = dtTask.Rows[i]["MEMO"].ToString();
dt.Rows.Add(dr);
}
this.SGVTask.DataSource = dt;
this.SGVTask.DataBind();
页面
<Columns>
<asp:TemplateField SortExpression="YMD">
<ItemTemplate>
<%#Eval("YMD")%>
</ItemTemplate>
</asp:TemplateField>
。。。。
</columns>
热心网友
时间:2022-04-12 01:06
dataGridView1设定名称的时候,将数据库里对应的列名同事设置绑定即可
热心网友
时间:2022-04-12 02:41
select 字段名 as 你定义的列名 *from 表名