代码如下:
Dim cnConn As New SqlConnection(ConfigurationSettings.AppSettings("Link"))
Dim SQL As String = "SELECT BNo FROM JobSheet WHERE JobNo ='ZL0801-001'"
Dim DR As SqlDataReader
Dim CMD As New SqlCommand(SQL, cnConn)Try
If cnConn.State = ConnectionState.Closed Then
cnConn.Open()
End If If DR.Read Then 《=======这行出错!!!
DR = CMD.ExecuteReader()
BN = Trim(DR("BNo"))
TextBox1.Text = BN
End If DR.Close()
cnConn.Close()
Catch ex As Exception
End Try错误如下:
System.NullReferenceException: 未将对象引用设置到对象的实例。
Dim cnConn As New SqlConnection(ConfigurationSettings.AppSettings("Link"))
Dim SQL As String = "SELECT BNo FROM JobSheet WHERE JobNo ='ZL0801-001'"
Dim DR As SqlDataReader
Dim CMD As New SqlCommand(SQL, cnConn)Try
If cnConn.State = ConnectionState.Closed Then
cnConn.Open()
End If If DR.Read Then 《=======这行出错!!!
DR = CMD.ExecuteReader()
BN = Trim(DR("BNo"))
TextBox1.Text = BN
End If DR.Close()
cnConn.Close()
Catch ex As Exception
End Try错误如下:
System.NullReferenceException: 未将对象引用设置到对象的实例。
DR = CMD.ExecuteReader()改为
DR = CMD.ExecuteReader()
If DR.Read Then
{
if(_dr.Read())
{
.........
}
}
If DR.Read Then
BN = Trim(DR("BNo"))
TextBox1.Text = BN