[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

.NET error end of statement expected

Posted on 2012-08-19
8
Medium Priority
?
447 Views
Last Modified: 2012-08-19
Im getting the errors in the while loop on lines 22 & 23
dr[FirstName].ToString() is underlined blue
and the one under it as well the same thing

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim db As New databaseConnection()
        db.OpenConnection()
        Dim comboText As String
        Dim comboValue As String
        Dim myArrayList As New ArrayList
        Dim cmd As New MySqlCommand
        Dim sqlQuery As String = "SELECT * FROM customers WHERE"
        If searchBy <> "" Then
            sqlQuery += " " & searchBy & "='" & TextBox1.Text & "' and"
        End If
        sqlQuery = sqlQuery & " merchantId=" & Form1.mMerchantId
        ' MessageBox.Show(sqlQuery)
        cmd.CommandText = sqlQuery

        Dim dr As MySqlDataReader = db.DataReader(cmd)

        If dr.HasRows() Then
            While dr.Read()
                comboText = ""
                comboValue = ""
                comboText = dr[FirstName].ToString() 
                comboValue = dr[customerId].ToString()
                myArrayList.Add(New ComboBoxValues(comboText, comboValue))


                ComboBox4.DataSource = myArrayList
                ComboBox4.DisplayMember = "DisplayMember"
                ComboBox4.ValueMember = "ValueMember"
            End While
        End If
    End Sub

Open in new window

0
Comment
Question by:prowebinteractiveinc
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 16

Expert Comment

by:Ady Foot
ID: 38309509
Does the FirstName field definitely exist within the data table?  That would be the obvious problem without looking in too much detail.
0
 

Author Comment

by:prowebinteractiveinc
ID: 38309532
there is no way for the program to know that. FirstName comes from a mysql Database
Im used to using dr(0)

I also just encountered another error. my datareader is only picking up one result. where I know it should be returning more then one ?
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 38309543
you are implicitly calling the Item property of the DataReader object. It can only takes an integer in parameter. Check http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.item(v=vs.71)
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 38309545
SQUARE brackets are used in C#.

    comboText = dr[FirstName].ToString();

You need PARENTHESIS:

    comboText = dr(FirstName).ToString()
0
 

Author Comment

by:prowebinteractiveinc
ID: 38309547
so how can I define the field name instead ?
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 38309552
*If those are the actual column names then you need a string literal too:

    comboText = dr("FirstName").ToString()
0
 

Author Comment

by:prowebinteractiveinc
ID: 38309553
idle_Mind, I tried what you mentioned it didnt work - gave a bigger error...
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 38309554
>>so how can I define the field name instead ?

not possible with a DataReader. You will need to use a DataTable instead

If you want to keep the DataReader, change SELECT * for SELECT customerId, FirstName so that you can use 0 and 1 in parameters. Using Select * is not in the best practices anyway
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Loops Section Overview
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question