我有這樣的代碼:如何將後期綁定語法轉換爲vb.net中的早期綁定語法?
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
,並即時得到以下錯誤:
Error 1: Option Strict On disallows late binding.
進出口使用上運行的Windows 7操作系統 一個GATEWAY筆記本多數民衆贊成的Visual Basic 2010速成如何解決這個錯誤?
正確的答案是,ListBox1.Items.Add不需要String類型。可以添加對象並調用它們的.ToString()方法,除非有自定義的DrawItem實現。 –