【发布时间】:2012-08-16 19:56:39
【问题描述】:
我的代码是
Public Function resload()
Dim conn As MySqlConnection = New MySqlConnection(ConfigurationManager.ConnectionStrings("connectionrms").ConnectionString) ''line 18
Dim comm As MySqlCommand = New MySqlCommand()
Dim dr As MySqlDataReader
conn.Open()
comm = New MySqlCommand("Select distinct name from restaurant", conn)
dr = comm.ExecuteReader()
While dr.Read() <> Nothing
headresnamecombo.Items.Add(dr(0).ToString())
End While
dr.Close()
headresnamecombo.SelectedIndex = 0
conn.Close()
Return Nothing
End Function
我的错误
在 C:\Users\Azinova7\Documents\Visual Studio 2008\Projects\Rest\Rest\billingBody.vb:第 18 行中的 Rest.billingBody.resload() 处
在 C:\Users\Azinova7\Documents\Visual Studio 2008\Projects\Rest\Rest\billingBody.vb:line 229 中的 Rest.billingBody.billingBody_Load(Object sender, EventArgs e) 处
在 System.Windows.Forms.UserControl.OnLoad(EventArgs e)
在 System.Windows.Forms.UserControl.OnCreateControl()
在 System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
在 System.Windows.Forms.Control.CreateControl()
在 System.Windows.Forms.Control.ControlCollection.Add(控制值)
在 System.Windows.Forms.Form.ControlCollection.Add(控制值)
在 System.Windows.Forms.Design.ControlDesigner.DesignerControlCollection.Add(Control c)
之后都是相同的连接代码
【问题讨论】:
-
我在上面的代码中看到了 mysqlconnection 对象创建
-
第一个问题:
dr.Read返回一个布尔值,所以你应该只有While dr.Read()。您还应该使用Using语句...