Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
Try Dim Conn As New OleDbConnection("Provider=SQLOLEDB;" & "Data Source=localhost;" & "Initial Catalog=test;User ID=sa;password=123") Dim Sqlstr As String = "select Subject,article from board where ArticleNo=30 "
Dim Cmd As New OleDbCommand(Sqlstr, Conn)
Dim reader As OleDbDataReader
Conn.Open()
reader = Cmd.ExecuteReader()
Label1.Text = reader("Subject") **** 它说 不存在此行/此列.....我数据库明明有字段的~~~~
Conn.Close()
Catch err As Exception
Label1.Text = "Error reading the database."
Label1.Text &= err.Message
End Try
End Sub
Try Dim Conn As New OleDbConnection("Provider=SQLOLEDB;" & "Data Source=localhost;" & "Initial Catalog=test;User ID=sa;password=123") Dim Sqlstr As String = "select Subject,article from board where ArticleNo=30 "
Dim Cmd As New OleDbCommand(Sqlstr, Conn)
Dim reader As OleDbDataReader
Conn.Open()
reader = Cmd.ExecuteReader()
Label1.Text = reader("Subject") **** 它说 不存在此行/此列.....我数据库明明有字段的~~~~
Conn.Close()
Catch err As Exception
Label1.Text = "Error reading the database."
Label1.Text &= err.Message
End Try
End Sub
Label1.Text = reader.files("Subject") **** 它说 不存在此行/此列.....我数据库明明有字段的~~~~
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim conn As New SqlConnection()
Dim Cmd As New SqlCommand("select * from Employees ", conn)
' Cmd.CommandText = "select * from employee "
conn.ConnectionString = "Data Source=.;Initial Catalog=Northwind;Persist Security Info=True;User ID=sa;Password="
Dim reader As SqlDataReader
Dim previousConnectionState As ConnectionState = conn.State
Try
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
reader = cmd.ExecuteReader()
Using reader
While reader.Read Console.WriteLine(reader.GetValue(0)) '指定的列
Console.WriteLine(reader.Item("LastName")) '按列名取值
End While
End Using
Finally
If previousConnectionState = ConnectionState.Closed Then
conn.Close()
End If
End Try End Sub
End Class