想不用SQL Server直接将.sql文件加载到datatable
vb.net吧
全部回复
仅看楼主
level 7
暴牙归来 楼主
本来在SQL问题语句还没解决以前想用读取普通文本代码加上数据结构栈来把数据加进datatable里面,但加进去后来发现数据与列不对应
这是原始sql文件添加表代码
2019年12月05日 07点12分 1
level 7
暴牙归来 楼主
下面是代码:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If sr.Peek() > -1 Then
varLine = sr.ReadLine()
varLine = varLine.Replace("[kms]", "[district]")
If varLine <> "" Then
If varLine.Contains("INSERT INTO") = True Then
Me.TextBox1.Text = varLine
Dim rowindex As Integer = 1
Dim instructioncodelength As Integer = 0
Me.ProgressBar1.Maximum = varLine.Length
Me.ProgressBar1.Minimum = 0
Me.ProgressBar1.Value = instructioncodelength
2019年12月05日 07点12分 2
level 7
暴牙归来 楼主
For Each c As String In varLine
If st.Count > 0 Then
Dim stacktopelement As String = st.Peek
If c <> ")" Then
If stacktopelement <> c Then
If c <> "'" Then
Try
If c = "," Then
If rowindex = 2 Then
st.Push(c)
ElseIf rowindex = 4 Then
st.Push(c)
ElseIf rowindex = 5 Then
st.Push(c)
ElseIf rowindex = 6 Then
st.Push(c)
ElseIf rowindex = 7 Then
st.Push(c)
End If
Else
data &= c
End If
Catch ex As Exception
End Try
Else
st.Push(c)
End If
Else
st.Pop()
If rowindex = 10 Then
Column10 = data
ElseIf rowindex = 9 Then
Column9 = data
ElseIf rowindex = 8 Then
Try
Column8 = data
Catch ex As Exception
Column8 = 0
End Try
ElseIf rowindex = 7 Then
Column7 = data
ElseIf rowindex = 6 Then
Try
Column6 = data
Catch ex As Exception
Column6 = 0
End Try
ElseIf rowindex = 5 Then
Column5 = data
ElseIf rowindex = 4 Then
Column4 = "NULL"
ElseIf rowindex = 3 Then
Try
Column3 = data
Catch ex As Exception
Column3 = 0
End Try
ElseIf rowindex = 2 Then
Column2 = data
Else
Column1 = data
End If
rowindex += 1
data = String.Empty
End If
Else
2019年12月05日 07点12分 3
level 7
暴牙归来 楼主
st.Pop()
rowindex = 0
newRow = dt.NewRow()
newRow("ID") = Column1
newRow("name") = Column2
newRow("adcode") = Column3
newRow("dataother") = Column4
newRow("citycode") = Column5
newRow("lat") = Column6
newRow("lng") = Column7
newRow("level") = Column8
newRow("parentid") = Column9
newRow("sort") = Column10
dt.Rows.Add(newRow)
data = String.Empty
End If
Else
If c = "(" Then
st.Push(c)
End If
End If
instructioncodelength += 1
Me.ProgressBar1.Value = instructioncodelength
Next
End If
Else
Exit Sub
End If
Else
Me.Timer1.Stop()
My.Forms.Form2.Show()
end if
end sub
2019年12月05日 07点12分 4
level 11
看不懂这波操作,原文件长啥样
2019年12月05日 23点12分 5
level 12
龅牙又复活了???
2019年12月06日 06点12分 6
是的
2019年12月06日 06点12分
level 12
好久没看到你了啊
2019年12月06日 06点12分 7
我也是。还有能不能不要再开一楼,和字节回复我就可以了
2019年12月06日 07点12分
2019年12月06日 09点12分
1