vb.net读取不同数据的方式(1)
用于读取text文档的数据If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
Try
Dim sr As New (OpenFileDialog1.FileName)
Do While endof = False
vin = sr.ReadLine.Substring(0, 17)
SelectStr = "select * from saomiaovin where vin= '" & vin & "' "
Dim Resault As DataTable
Resault = AccessOperation.ACCESSOperate(SelectStr, msg)
If Resault.Rows.Count = 0 Then
'MsgBox(vin + "已经扫描过,将覆盖该VIN号")
InsertStr = "insert into saomiaovin values('" & vin & "') "
AccessOperation.ACCESSOperate(InsertStr, msg)
End If
endof = sr.EndOfStream
Loop
sr.Close()
MsgBox("数据导入成功!")
Catch
MsgBox(Err.Description)
End Try
End If
读取excle的数据
If Me.OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim str As String = Me.OpenFileDialog1.FileName
Dim cn As System.Data.OleDb.OleDbConnection
Dim cmd As System.Data.OleDb.OleDbDataAdapter
Dim ds As New System.Data.DataSet()
MsgBox(str)
cn = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;" & _
"data source= " & str & ";Extended Properties=Excel 8.0;")
' Select the data from Sheet1 of the workbook.
cmd = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", cn)
cn.Open()
cmd.Fill(ds)
cn.Close()
Dim table As DataTable = ds.Tables(0)
Me.DataGridView1.DataSource = table
End If