daniel11
daniel11

Reputation: 2041

how do i convert late binding syntax to early binding syntax in vb.net?

i have this code:

 Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Try
        ' retrieving the administration table.
        con.Open()
        DataAdapter1.SelectCommand = sqladmin
        DataAdapter1.Fill(ds, "stratos")
        DataGridView1.DataSource = ds
        DataGridView1.DataMember = "stratos"
        con.Close()
    Catch myerror As MySqlException
        MessageBox.Show("Error Retrieving Administration Table: " & myerror.Message)
    End Try


    Try
        ' retrieving the projects list.
        con.Open()
        DataAdapter2.SelectCommand = sqlprojects
        DataAdapter2.Fill(ds2, "projects")
        ListBox1.Items.Clear()

        For Each DataRow In ds2.Tables("projects").Rows

            ' ##### THE ERROR OCCURS ON THE LINE BELOW: ##### '

            ListBox1.Items.Add(DataRow("project_name"))
        Next
        con.Close()

    Catch myerror As MySqlException
        MessageBox.Show("Error Retrieving Projects List: " & myerror.Message)
    End Try

and im getting the following error:

Error 1: Option Strict On disallows late binding.

Im using visual basic 2010 express on a gateway laptop thats running Windows 7 OS How do i resolve this error?

Upvotes: 0

Views: 1759

Answers (2)

Joel Coehoorn
Joel Coehoorn

Reputation: 416131

That usually mean you Dim'd a variable or declared a function with no type. The DataRow used in your For Each loop might be the culprit. The other is that items in a DatRow are of type object; you should cast them or otherwise convert them to a specific type. You want this instead:

For Each dr As DataRow in d2.Tables("projects").Rows
   '...

   ListBox1.Items.Add(dr("project_name").ToString())
Next dr

Upvotes: 2

CapOb
CapOb

Reputation: 46

You will need to change the loop with the error to the following:

For Each dr as DataRow In ds2.Tables("projects").Rows 

  ' ##### THE ERROR OCCURS ON THE LINE BELOW: ##### ' 

  ListBox1.Items.Add(Convert.ToString(dr("project_name"))) 
Next 

Upvotes: 3

Related Questions