[RESOLVED] Datareader doubt
This code is not giving the msgbox value! Is the GetValue method incorrect?
Code:
Dim myDBConnection As SqlClient.SqlConnection = Nothing
Dim myDBCommand As SqlClient.SqlCommand = Nothing
Dim myDBReader As SqlClient.SqlDataReader = Nothing
Try
myDBConnection = New SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=D:\ProjectMW\MachineWale\MachineWale\DatabaseMW.mdf;Integrated Security=True;User Instance=True")
myDBConnection.Open()
myDBCommand = New SqlClient.SqlCommand("SELECT MAX(ClientID) FROM ClientProfile", myDBConnection)
myDBReader = myDBCommand.ExecuteReader(CommandBehavior.CloseConnection)
If myDBReader.HasRows Then
myDBReader.Read()
MsgBox(myDBReader.GetValue("ClientID") + 1)
'Me.TextBox2.Text = myDBReader.Item("ClientID".ToUpper) + 1
Else
Me.TextBox2.Text = "1000"
End If
Catch ex As Exception
MsgBox(" Error in Connection! ")
Exit Try
Exit Sub
Finally
'CLEAN UP DB OBJECTS
If myDBReader IsNot Nothing Then myDBReader.Close()
If myDBCommand IsNot Nothing Then myDBCommand.Dispose()
If myDBConnection IsNot Nothing Then myDBConnection.Close()
End Try