Results 1 to 7 of 7

Thread: [RESOLVED] Datareader doubt

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Resolved [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
    Last edited by LuxCoder; Oct 30th, 2009 at 05:04 AM. Reason: Coding

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width