如何从gridview插入多个行到数据库? [英] how to insert multiple rows from gridview into database?

查看:154
本文介绍了如何从gridview插入多个行到数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我正在尝试将gridviw中的多行插入数据库?

这样的

hi all

I''m trying to insert multiplte rows from gridviw into database?

like that

for (int i = 0; i < dt.Rows.Count; i++)
            {
                Items it = new Items(dt.Rows[i]["Name"].ToString(), dt.Rows[i]["Code"].ToString());
                it.insert();

            }


但它仅插入第一行,而忽略其他

我该怎么做才能插入所有行?
预先大于thanx


but it inserts only the first row and ignore the other

what can I do to insert all rows ??
thanx in advance

推荐答案

问题似乎是您确实没有在任何地方插入new Item .您正在调用it.insert(),但调用中没有任何新项目的构造函数来指示有什么地方可以插入新对象!

也许这没有帮助,但是您可能对所编码的内容不完整.
The problem seems to be that you are really not inserting the new Item anywhere. You are calling the it.insert() but there is nothing in the call for the constructor of new item to indicate that there is somewhere to insert the new object!!

Maybe this is not helpful, but you may have an incomplete explanation of what you are coding.


您好,sara,

我认为将多行插入数据库是一种不好的做法.

您应该尝试创建XML字符串,并将逻辑放入数据库端存储过程中并插入记录.

这也将减少连接数据库的往返行程.

Thnx ....
Hi sara,

I think this is bad practice to insert multiple row into database.

You should try to create XML string and put your logic in Database side stored procedure and insert record.

This will also decrease your round trip for connecting database.

Thnx....


这篇关于如何从gridview插入多个行到数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆