W
Woody Splawn
I have some code that looks like this:
Dim SSN, LName, FName, M As String
mySqlConnection = New SqlConnection(myConnectionString)
Dim sql_Command As New SqlCommand( _
"Select SSN, LName, FName, M from Students WHERE (SSN = " + " '" +
ProposedValue + "')", _
mySqlConnection)
Try
mySqlConnection.Open()
Dim myReader As SqlDataReader =
sql_Command.ExecuteReader(CommandBehavior.CloseConnection)
While myReader.Read()
SSN = myReader.GetString(0) ' The first field in the answer
set
LName = myReader.GetString(1) 'The second field in the
answer set
FName = myReader.GetString(2) 'The third field in the answer
set
'M = myReader.GetString(3) 'The fourth field in the answer
set
End While
myReader.Close()
sql_Command.Connection.Close()
The problem is that the field caled M (middle initial) is sometimes null.
When it is the code above fails. How can I write the code so that if the
middle initial field is blank or null the code won't crash?
Dim SSN, LName, FName, M As String
mySqlConnection = New SqlConnection(myConnectionString)
Dim sql_Command As New SqlCommand( _
"Select SSN, LName, FName, M from Students WHERE (SSN = " + " '" +
ProposedValue + "')", _
mySqlConnection)
Try
mySqlConnection.Open()
Dim myReader As SqlDataReader =
sql_Command.ExecuteReader(CommandBehavior.CloseConnection)
While myReader.Read()
SSN = myReader.GetString(0) ' The first field in the answer
set
LName = myReader.GetString(1) 'The second field in the
answer set
FName = myReader.GetString(2) 'The third field in the answer
set
'M = myReader.GetString(3) 'The fourth field in the answer
set
End While
myReader.Close()
sql_Command.Connection.Close()
The problem is that the field caled M (middle initial) is sometimes null.
When it is the code above fails. How can I write the code so that if the
middle initial field is blank or null the code won't crash?