Rss & SiteMap

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

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

标题:[求助]此段代码错在何处

1楼
ybmjy 发表于:2010/4/28 7:19:00
Dim Multi As String = "姓名,性别,年龄"
Dim Values() as String
Values = Multi.split(",")
For Index As Integer = 0 To Values.Length - 1
    if e.Form.Controls(Values(Index)).Value = nothing
        MessageBox.Show("对不起,您输入的信息不全,请录入<" & Values(Index) & ">后再继续!", "提示")
        e.Form.Controls(Values(Index)).Select()
        Return
    end if
    dim y as String = ""
    y = y & "," & Values(Index)
    dim s as String = ""
    s = s & ",'" & e.Form.Controls(Values(Index)).value & "'"
    Dim scm as New SQLCommand
    scm.ConnectionName  = "y"
    scm.CommandText = "Insert Into 民兵 " & "(" & y.Trim(",") & ")" & "" & "" & "Values(" & s.Trim(",") & ")"
    scm.ExecuteNonQuery
Next

在向后台数据库中写入控件值时,为何一个控件的值在后台就是一行。如上代码将在后台数据库中写入3行
2楼
狐狸爸爸 发表于:2010/4/28 8:59:00
加入一行:

scm.CommandText = "Insert Into 民兵 " & "(" & y.Trim(",") & ")" & "" & "" & "Values(" & s.Trim(",") & ")"
Messagebox.show(scm.CommandText)
scm.ExecuteNonQuery


看看你合成的SQL语句是否正确
3楼
ybmjy 发表于:2010/4/28 9:12:00
以下是引用狐狸爸爸在2010-4-28 8:59:00的发言:
加入一行:

scm.CommandText = "Insert Into 民兵 " & "(" & y.Trim(",") & ")" & "" & "" & "Values(" & s.Trim(",") & ")"
Messagebox.show(scm.CommandText)
scm.ExecuteNonQuery


看看你合成的SQL语句是否正确

控件值都能正确地写到相应的字段中,就是有几个控件就会增加几行,估计是循环语句的问题,可又不知如何弄了哈
图片点击可在新窗口打开查看

4楼
狐狸爸爸 发表于:2010/4/28 9:28:00
呵呵,你的scm.ExecuteNonQuery就在循环语句之中,每循环一次就插入一行,你应该将其挪到循环语句之外。

Dim Multi As String = "姓名,性别,年龄"
Dim Values() as String
Values = Multi.split(",")
dim y as String = ""
dim s as String = ""
For Index As Integer = 0 To Values.Length - 1
    if e.Form.Controls(Values(Index)).Value = nothing
        MessageBox.Show("对不起,您输入的信息不全,请录入<" & Values(Index) & ">后再继续!", "提示")
        e.Form.Controls(Values(Index)).Select()
        Return
    end if
    y = y & "," & Values(Index)
    s = s & ",'" & e.Form.Controls(Values(Index)).value & "'"
Next
Dim scm as New SQLCommand
scm.ConnectionName  = "y"
scm.CommandText = "Insert Into 民兵 " & "(" & y.Trim(",") & ")" & "" & "" & "Values(" & s.Trim(",") & ")"
scm.ExecuteNonQuery

大概就是这样,你自己调试一下吧

图片点击可在新窗口打开查看
5楼
ybmjy 发表于:2010/4/28 9:31:00
搞定,谢谢
共5 条记录, 每页显示 10 条, 页签: [1]

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

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