Imports system
Imports System.Data
Imports System.Data.OleDb
Module Module1
Sub Main()
Dim sConnectionString, sSQL As String
sConnectionString = "provider=Microsoft.Jet.OLEDB.4.0;data source=D:\编程区\VB.NET工程\Null.MDB"
sSQL = "SELECT 产品名称 from null ORDER BY 产品ID ASC"
Dim MyCon As New OleDb.OleDbConnection(sConnectionString)
Dim cmdF As New OleDb.OleDbCommand(sSQL, MyCon)
cmdF.CommandText = sSQL
cmdF.Connection = MyCon
cmdF.CommandType = CommandType.Text
Try
MyCon.Open()
Console.WriteLine("建立正确连接")
Console.ReadLine()
Catch OleDbe As OleDbException
Console.WriteLine("连接失败")
Exit Sub
End Try
Dim MyDataReader As OleDbDataReader
MyDataReader = cmdF.ExecuteReader() 此句出现异常——不知道错在哪里了~高手指点啊
Do While (MyDataReader.Read())
Console.WriteLine(MyDataReader.Item("产品名称"))
Loop
MyDataReader.Close()
MyCon.Close()
Console.ReadLine()