Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共8 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:下面这段代码可以向后台数据库写入数据吗?

1楼
lpxjw_zyl 发表于:2010/3/17 9:31:00

for i as Double = 10000001 to 1000099

Dim cmd As New SQLCommand
cmd.CommandText = "Insert Into Xssj (_Identify,编号,产品) Values('" & i & "'100,'PD01')"
cmd.C
cmd.ExecuteNonQuery()
next

2楼
lpxjw_zyl 发表于:2010/3/17 9:37:00
我试上述代码不报错,可是不增加数据,请帮忙解决。
3楼
lpxjw_zyl 发表于:2010/3/17 9:39:00

for i as Double = 10000001 to 1000099

Dim cmd As New SQLCommand
cmd.C
cmd.CommandText = "Insert Into Xssj (_Identify,编号,产品) Values('" & i & "'100,'PD01')"

cmd.ExecuteNonQuery()
next


代码是这个代码,请问错在哪儿
4楼
lpxjw_zyl 发表于:2010/3/17 9:40:00

for i as Double = 10000001 to 1000099

Dim cmd As New SQLCommand
cmd.C
cmd.CommandText = "Insert Into Xssj (_Identify,编号,产品) Values('" & i & "'100,'PD01')"

cmd.ExecuteNonQuery()
next

5楼
lpxjw_zyl 发表于:2010/3/17 9:40:00

for i as Double = 10000001 to 1000099

Dim cmd As New SQLCommand
cmd.C
cmd.CommandText = "Insert Into Xssj (_Identify,编号,产品) Values('" & i & "'100,'PD01')"

cmd.ExecuteNonQuery()
next

6楼
lxl 发表于:2010/3/17 9:46:00
以下是引用lpxjw_zyl在2010-3-17 9:31:00的发言:

for i as Double = 10000001 to 1000099

Dim cmd As New SQLCommand
cmd.CommandText = "Insert Into Xssj (_Identify,编号,产品) Values('" & i & "'100,'PD01')"
cmd.C
cmd.ExecuteNonQuery()
next

_Identify列如果不是自动增量列的话 可以。

代码还能修改一下:
 Dim cmd As New SQLCommand
 cmd.C
 for i as Double = 10000001 to 1000099
      cmd.CommandText = "Insert Into Xssj (_Identify,编号,产品) Values('" & i & "'100,'PD01')"
      cmd.ExecuteNonQuery()
 next
这边能避免在循环中申明变量


 

7楼
lxl 发表于:2010/3/17 9:58:00

    Dim cmd As New SQLCommand
    cmd. Connectionname = "aaa"
    cmd.CommandText   = "set IDENTITY_INSERT Xssj ON " 
    cmd.CommandText &= "Declare @i int "  
    cmd.CommandText &= "set @i = 10000001 "  
    cmd.CommandText &= "while @i < 10000100 " 
    cmd.CommandText &= "begin " 
    cmd.CommandText &= "Insert Into Xssj (_Identify,编号,产品) Values(@i,100,'PD01') " 
    cmd.CommandText &= "set @i = @i + 1 " 
    cmd.CommandText &= "end " 
    cmd.CommandText &= "set IDENTITY_INSERT Xssj OFF
"
    cmd.ExecuteNonQuery()


只向数据库提交一次请求,而原来的代码要提交100次请求。
_Identify是自增列也能正常插入

8楼
lpxjw_zyl 发表于:2010/3/17 10:10:00
for i as Double = 1000001 To 1000009
    Dim cmd As New SQLCommand
    cmd.C
    cmd.CommandText = "Insert Into Xssj (_Identify,编号,校名) Values('" & i & "',100,'重庆市梁平县')"
    cmd.ExecuteNonQuery()
    output.show(i)
next
共8 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .05078 s, 2 queries.