OLEDB - select Count not working

筅森魡賤 提交于 2019-12-12 04:42:44

问题


Find below what I've done so far, but unfortunately it's not working.

       Private BS as New BindingSource
       Dim ds As New DataSet
     ' Make the Connection
       Using con As New OleDb.OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = Database1.mdb")
       con.Open()
       Dim Sql = "SELECT COUNT ([Eventname]) FROM Eventproposal"
       Dim da = New OleDb.OleDbDataAdapter(Sql, con)
       da.Fill(ds, "Eventproposal")
     ' Set the Binding Source
      bs.DataSource = ds.Tables("Eventproposal")
     con.Close()
 End Using
    TextBox1.DataBindings.Add("Text", bs, "")

回答1:


Couple things, you should end all SQL Commands to MS Access with ;

Dim Sql = "SELECT COUNT ([Eventname]) FROM Eventproposal;"

And you did not name your column which will give you an error when you attempt to access it by name.

Dim Sql = "SELECT COUNT ([Eventname]) AS Eventname FROM Eventproposal;"

I believe it will give it a name but not what your thinking. Lastly, when you do your binding, you will have to reference the name of the field in the table.

TextBox1.DataBindings.Add("Text", bs, "Eventname")


来源:https://stackoverflow.com/questions/25967055/oledb-select-count-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!