如何在sqlserver中将多个数据保存到数据库中.... [英] How To save multiple data into database in sqlserver....

查看:111
本文介绍了如何在sqlserver中将多个数据保存到数据库中....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将列表数据保存到sqlserver数据库中.....



我想一次从Aspx页面保存多行到sqlserver。

How to save a list data into sqlserver database.....

I want to save multiple row at one time from Aspx page to sqlserver.

推荐答案

通过文章了解多种方式进行多次插入 [ ^ ]。



最简单的方法是创建一个XML字符串并将其发送到存储过程和过程内部,读取值并插入表格。



参见一个例子 - 插入使用asp.net的单个命令中的多行 [ ^ ]。
Go through the Article to know Multiple Ways to do Multiple Inserts[^].

The easiest way is to create one XML string and send that to the Stored Procedure and inside the Procedure, read the values and insert to table.

See one example- Inserting multiple rows in single command using asp.net[^].


您应该将记录作为sqldbType.structur表传递ED。并在数据库程序中处理该表。



在数据库中创建一个类型:



You should pass your records as table as "sqldbType.structured". and in database procedure handle the table.

in database create a type:

CREATE TYPE LogData AS TABLE(
 [Date] [varchar](20) NULL,
 [Scbytes] [bigint] NULL,
 [CsHost] [varchar](256) NULL
)





然后在程序中使用该类型







then use that type in procedure


[prc_insertlog]
       @intClientID INT ,
      @tlbLogData  LogData READONLY





在aspx页面中,只需使用Type中的字段创建一个数据表。并传入程序。



在sql server中,你应该创建游标。打开游标并逐个获取行。并循环直到@@ FETCH_STATUS = 0.



希望您的问题得到整理:)



In aspx page just create a datatable with the fields as in Type. and pass in the procedure.

In sql server, you should create cursor. OPen cursor and fetch the rows one by one. and loop until @@FETCH_STATUS = 0.

Hope your problem will be sorted out :)


这篇关于如何在sqlserver中将多个数据保存到数据库中....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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