vb读出txt文档并且写进数据库
例如:第一行:“555~~~0400~~~~~~上海~~”双引号不算,注意间隔符是~第一行:55-54~~上海~~~~车轮~~~~~~~245.000第二行:21-71~...
例如:第一行:“ 555~~~0400~~~~~~上海~~ ”
双引号不算,注意间隔符是~
第一行:55-54~~上海~~~~车轮~~~~~~~245.000
第二行:21-71~~广州~~~~围巾~~~~~~~800.000
第三行:…………………………………………
依次类推,读出来并写进sql数据库,答案要求完整点,最好带上注释
考试的原题目是这样的:
第一行:100005~~5500000016~~20090213~~00010~~~~~~X630015J-B0100~~后地板左前阻尼片~~735200.000~~EA~~EA~~735200.000~~~~1100~~S001~~中心库~~~~~~800.000~~~~
第二行:100005~~5500000016~~20090213~~00020~~~~~~X630016J-B0100~~后地板右前阻尼片~~735200.000~~EA~~EA~~735200.000~~~~1100~~S001~~中心库~~~~~~800.000~~~~
依次循环 展开
双引号不算,注意间隔符是~
第一行:55-54~~上海~~~~车轮~~~~~~~245.000
第二行:21-71~~广州~~~~围巾~~~~~~~800.000
第三行:…………………………………………
依次类推,读出来并写进sql数据库,答案要求完整点,最好带上注释
考试的原题目是这样的:
第一行:100005~~5500000016~~20090213~~00010~~~~~~X630015J-B0100~~后地板左前阻尼片~~735200.000~~EA~~EA~~735200.000~~~~1100~~S001~~中心库~~~~~~800.000~~~~
第二行:100005~~5500000016~~20090213~~00020~~~~~~X630016J-B0100~~后地板右前阻尼片~~735200.000~~EA~~EA~~735200.000~~~~1100~~S001~~中心库~~~~~~800.000~~~~
依次循环 展开
4个回答
展开全部
Dim Conn As ADODB.Connection
Dim ConnectionString As String
Dim strSQL As String
Set Conn = New ADODB.Connection
ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=True;"
ConnectionString = ConnectionString & "User ID=" & "用户名" & ";Password=" & "密码" & ";"
ConnectionString = ConnectionString & "Initial Catalog=" & "数据库名" & ";Data Source=" & "服务器名"
Conn.Open ConnectionString
Dim a As String, b() As String
Open "c:\abc.txt" For Input As #1
While Not Eof(1)
Line Input #1, a
For i = 1 To 5
a = Replace(a, "~~", "~")
Next
b = Split(a, "~")
strSQL = "Insert Into 表名("
strSQL = strSQL & "'" & b(0) & "'"
for i=1 to UBound(b)
strSQL = strSQL & ",'" & b(i) & "'"
next
strSQL = strSQL & ")"
Conn.Execute strSQL
Wend
Close #1
上面的“服务器名”、“数据库名”、“表名名”、“用户名”、“密码”你都要用真实的代进去
Dim ConnectionString As String
Dim strSQL As String
Set Conn = New ADODB.Connection
ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=True;"
ConnectionString = ConnectionString & "User ID=" & "用户名" & ";Password=" & "密码" & ";"
ConnectionString = ConnectionString & "Initial Catalog=" & "数据库名" & ";Data Source=" & "服务器名"
Conn.Open ConnectionString
Dim a As String, b() As String
Open "c:\abc.txt" For Input As #1
While Not Eof(1)
Line Input #1, a
For i = 1 To 5
a = Replace(a, "~~", "~")
Next
b = Split(a, "~")
strSQL = "Insert Into 表名("
strSQL = strSQL & "'" & b(0) & "'"
for i=1 to UBound(b)
strSQL = strSQL & ",'" & b(i) & "'"
next
strSQL = strSQL & ")"
Conn.Execute strSQL
Wend
Close #1
上面的“服务器名”、“数据库名”、“表名名”、“用户名”、“密码”你都要用真实的代进去
展开全部
555~~~0400~~~上海
可以把分隔符设置3个~这样容易编点
Open 文本地址 For Input As #1
print #1,str1
For i = 1 To Len(str1)
If Mid(str1, i, 4) = "~~~" Then
j = j + 1
End If
Next i
str2 = Split(str1, "~~~", j + 1)
现在可以把str2的字符串写禁数据库了
str2(0)是555
str2(1)是0400
str2(2)是上海
可以把分隔符设置3个~这样容易编点
Open 文本地址 For Input As #1
print #1,str1
For i = 1 To Len(str1)
If Mid(str1, i, 4) = "~~~" Then
j = j + 1
End If
Next i
str2 = Split(str1, "~~~", j + 1)
现在可以把str2的字符串写禁数据库了
str2(0)是555
str2(1)是0400
str2(2)是上海
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
很简单
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
easy
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |