| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 460 人关注过本帖
标题:怎么往 SQL 表里插入数据,求大师帮忙,谢谢!!
只看楼主 加入收藏
cailinru
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2014-7-30
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
怎么往 SQL 表里插入数据,求大师帮忙,谢谢!!
让表里自动生成数据

代码如下
Private Sub Command1_Click()
 Dim c As Integer
    Dim d As Integer
    Dim e As Integer
    Dim k As String
    Dim i As Integer
Set rs = Nothing
      c = 200
      d = 200
For e = 200 To 206
      e = e + 1
      k = CStr(c) + "." + CStr(d) + "." + CStr(e)
    For i = 0 To 255
      i = i + 1
       sql = "Insert into IPDB (号段,IP号) VALUES (" & k & "," & i & ")"
    Set rs = SelectSQL(sql, msg)
    Set Me.DataGrid1.DataSource = rs
    DataGrid1.Refresh
    Next
    Next
  End Sub
2014-09-01 10:36
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4947
专家分:30084
注 册:2008-10-15
收藏
得分:20 
sql = "Insert into IPDB (号段,IP号) VALUES (" & k & "," & i & ")"
    Set rs = SelectSQL(sql, msg)

我记得 SQL Insert 没有返回,也就是说      Set rs = SelectSQL(sql, msg) 取不到结果。

使用 数据连接的 执行 SQL 的功能直接执行这个 SQL 命令。

授人于鱼,不如授人于渔
早已停用QQ了
2014-09-01 14:37
cailinru
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2014-7-30
收藏
得分:0 
回复 2 楼 风吹过 b
你说的对,现在这个提示'.200'附近有语法错误
Private Sub Command1_Click()
   On Error GoTo ErrMsg
    Dim sq1 As String
    Dim c As Integer
    Dim d As Integer
    Dim e As Integer
    Dim k As String
    Dim i As Integer

Set cn = New ADODB.Connection
cn.ConnectionString = "provider=msdasql;dsn=ss"
cn.Open
      c = 200
      d = 200
For e = 200 To 206
      For i = 1 To 255
      k = CStr(c) + "." + CStr(d) + "." + CStr(e) + "." + CStr(i)
       cn.Execute ("Insert into IPDB (IP号) VALUES (" & k & ")")
  
    Next
Next
Set rs = Nothing
sql = "select * from IPDB "
    Set rs = SelectSQL(sql, msg)
    Set Me.DataGrid1.DataSource = rs
    DataGrid1.Refresh
    rs.Close
ErrMsg:
    MsgBox err.Description, vbExclamation, "出错"
End Sub
2014-09-02 09:05
快速回复:怎么往 SQL 表里插入数据,求大师帮忙,谢谢!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023880 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved