GridView 如何绑定数据库拜托各位大神

GridView 如何绑定数据库拜托各位大神,第1张

datatabel ndt=new datatabel(); ndt=dbbasegetdatatabel(sql); GridView1datasource=ndt; databind();

本人纯手打,望采纳!!

1 可以采用数据绑定,代码如下:

SqlConnection con=new SqlConnection("Server=;Uid=sa;Pwd=sa;Database=Test"); //连接数据库

SqlDataAdapter da=new SqlDataAdapter("SELECT FROM you",con); //比如要查询的是油表

DataSet ds=new DataSet();

daFill(ds); //将表中的数据填充到适配器里

thisGridViewDataSorce = dsTables[0]; //将表中的数据绑定到GridView控件中,显示的效果可以用GridView的样式模板实现

2 修改,查看,查询

用GridView里的模板实现=>添加模板 => 将模板中加入控件,再在控件上加该就显示成这样子了,查询的话在模板中加按钮,按钮上面再加。

这就是制作的全过程,具体得自己 *** 作了! 祝你成功

SqlCommand cmdy = new SqlCommand("insert into OrdersDetail (OrderId,ProductId,Quantity,UnitCost,ProductName) values ('" + top1Id + "','" +GridView1Rows[i]RowIndexToString() + "','" + ((Label)GridView1Rows[i]FindControl("PNumber"))Text + "','" + ((Label)GridView1Rows[i]FindControl("PMemberPrice"))Text + "','" + ((Label)GridView1Rows[i]FindControl("PName"))Text + "'",cn);

cmdyExecuteNonQuery();

你原来的这程式有错没有错误提示什么呀,你又不告诉我们,如果没有错你只是想把很多个的访问数据库变成一次的话

你可以把那些insert的语句连去起来,再统一执行就可以了,SQL可以的,Orcale的话加上";"

例如这样

SqlCommand cmdx = new SqlCommand("select top 1 OrderId from Orders order by OrderId desc",cn);

string top1Id = cmdxExecuteScalar()ToString();

string[] asqls=new string [GridView1RowsCount];

string sql=stringEmpty;

for (int i = 0; i < GridView1RowsCount; i++)

{

sql=sql+"insert into OrdersDetail (OrderId,ProductId,Quantity,UnitCost,ProductName) values ('" + top1Id + "','" +GridView1Rows[i]RowIndexToString() + "','" + ((Label)GridView1Rows[i]FindControl("PNumber"))Text + "','" + ((Label)GridView1Rows[i]FindControl("PMemberPrice"))Text + "','" + ((Label)GridView1Rows[i]FindControl("PName"))Text + "' \n"

}

SqlCommand cmdy = new SqlCommand(sql,cn);

cmdyExecuteNonQuery();

以上就是关于GridView 如何绑定数据库拜托各位大神全部的内容,包括:GridView 如何绑定数据库拜托各位大神、.Net下DATAGRIDVIEW和SQL数据库连接问题、怎么样把GridView中的数据添加到数据库等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/9545963.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-29
下一篇2023-04-29

发表评论

登录后才能评论

评论列表(0条)

    保存