ExecuteReader: Connection 属性尚未初始化
来源:百度知道 编辑:UC知道 时间:2024/06/28 17:48:38
Imports System.Data.SqlClient
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
SqlConnection1.Open()
Dim rdCustomers As SqlDataReader
rdCustomers = _
SqlCommand1.ExecuteReader(CommandBehavior.CloseConnection)
Do While rdCustomers.Read
Console.WriteLine("身份证号码:" & rdCustomers.GetString(0) & _
" 姓名:" & rdCustomers.GetString(1) & " 房号:" & rdCustomers.GetString(2))
Loop
rdCustomers.Close()
End Sub
End Class
错误代码行:rdCustomers = SqlCommand1.ExecuteReader(CommandBehavior.CloseConnection)
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
SqlConnection1.Open()
Dim rdCustomers As SqlDataReader
rdCustomers = _
SqlCommand1.ExecuteReader(CommandBehavior.CloseConnection)
Do While rdCustomers.Read
Console.WriteLine("身份证号码:" & rdCustomers.GetString(0) & _
" 姓名:" & rdCustomers.GetString(1) & " 房号:" & rdCustomers.GetString(2))
Loop
rdCustomers.Close()
End Sub
End Class
错误代码行:rdCustomers = SqlCommand1.ExecuteReader(CommandBehavior.CloseConnection)
代码好像没有问题,你的数据库连接有没有问题?加个try试一下看
错误代码行:rdCustomers = SqlCommand1.ExecuteReader(CommandBehavior.CloseConnection)
这个方法你给的参数不对。
没有连接数据库
你跟踪下,看看SqlConnection1.Open()
是否成功