does anyone know what i do bad? I am trying to count number of rows in MS access Database
Here is code which i tried:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim conn As New OleDbConnection
conn.ConnectionString = ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\Test Database\Database.accdb")
conn.Open()
Dim strsql As String
strsql = "Select count(*) from TABLA" '" select Panel from PANELS where ID"
Dim cmd As New OleDbCommand(strsql, conn)
Dim myreader As OleDbDataReader
myreader = cmd.ExecuteReader
myreader.Read()
PanelsInDatabase = myreader.Item(strsql)
Label1.Text = PanelsInDatabase
conn.Close()
For i As Integer = 0 To PanelsInDatabase - 1
CreatePanels()
CreateDeleteButton(_PanelName)
CreateLabels(_PanelName)
CreateLabel2(_PanelName)
Next
End Sub
Thank you in advance
(if i start code i get an error: System.IndexOutOFRangeException)
ExecuteScalarif you want to get a single value. That said, you could callExecuteReader(ExecuteScalardoes internally) if you write code that makes sense but yours just doesn't. Where have you ever seen an example of indexing a data reader using aStringcontaining SQL code? You haven't. Every example using the numeric index of a column so why would you expect it to work any other way? - jmcilhinneySELECT 1 AS "SELECT 1 AS x FROM t" FROM t? :) - Caius Jard