UPDATE statement in VB connecting to Access - vb.net

I'm trying to update the position column in my access database but the problem is I'm having problem update that column while the rest of the column will not give out error message.
The error message: Syntax error in UPDATE statement, Microsoft JET database engine...
The code:
Dim myConnection As OleDbConnection = New OleDbConnection
Dim ds As New DataSet
Dim da As OleDbDataAdapter
Dim MaxRows As Integer
Dim i As Integer
Dim sql As String
Private Sub updateButton_Click(sender As Object, e As EventArgs) Handles updateButton.Click
Using myConnection = New OleDbConnection("Provider = Microsoft.ACE.OLEDB.12.0; Data Source =C:\LecturerDetail.mdb")
myConnection.Open()
Dim str As String
str = "UPDATE lecturer " & _
"SET [empName] = ?,[empId] = ?, [position] =?, [faculty] = ? " & _
" , [degree1] = ?, [degree2] = ?, [degree3] = ?,[degree] = ?, [empType] = ? " & _
" ,[icNo] = ?, [citizenship] = ?, [phoneNo] = ?, [email] = ?,[permitNo] = ? " & _
" , [permitStartDate] = ?, [permitEndDate] = ?, [pStatus] =?, [remark] =? " & _
" WHERE ([empId] = ?) "
Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
cmd.Parameters.AddWithValue("#empName", nameTxt.Text)
cmd.Parameters.AddWithValue("#empId", empIdTxt.Text)
cmd.Parameters.AddWithValue("#position", positionComboBox.SelectedText)
cmd.Parameters.AddWithValue("#faculty", facultyComboBox.SelectedText)
cmd.Parameters.AddWithValue("#degree1", empDeg1.Text)
cmd.Parameters.AddWithValue("#degree2", empDeg2.Text)
cmd.Parameters.AddWithValue("#degree3", empDeg3.Text)
cmd.Parameters.AddWithValue("#degree", empDeg4.Text)
cmd.Parameters.AddWithValue("#empType", empTypeComboBox.SelectedText)
cmd.Parameters.AddWithValue("#icNo", icTxt.Text)
cmd.Parameters.AddWithValue("#citizenship", citizenshipComboBox.SelectedText)
cmd.Parameters.AddWithValue("#phoneNo", phoneTxt.Text)
cmd.Parameters.AddWithValue("#email", emailTxt.Text)
cmd.Parameters.AddWithValue("#permitNo", permitNoTxt.Text)
cmd.Parameters.AddWithValue("#permitStartDate", DateTimePicker1.Text)
cmd.Parameters.AddWithValue("#permitEndDate", DateTimePicker2.Text)
cmd.Parameters.AddWithValue("#pStatus", statusComboBox.Text)
cmd.Parameters.AddWithValue("#remark", remark.Text)
cmd.Parameters.AddWithValue("#empId", empIdTxt.Text)
Try
cmd.ExecuteNonQuery()
Dim cb As New OleDb.OleDbCommandBuilder(da)
ds.Tables("lecturer").Rows(i).Item(0) = empIdTxt.Text
ds.Tables("lecturer").Rows(i).Item(1) = nameTxt.Text
ds.Tables("lecturer").Rows(i).Item(2) = positionComboBox.Text
ds.Tables("lecturer").Rows(i).Item(3) = facultyComboBox.Text
ds.Tables("lecturer").Rows(i).Item(4) = empDeg1.Text
ds.Tables("lecturer").Rows(i).Item(5) = empDeg2.Text
ds.Tables("lecturer").Rows(i).Item(6) = empDeg3.Text
ds.Tables("lecturer").Rows(i).Item(7) = empDeg4.Text
ds.Tables("lecturer").Rows(i).Item(8) = empTypeComboBox.Text
ds.Tables("lecturer").Rows(i).Item(9) = icTxt.Text
ds.Tables("lecturer").Rows(i).Item(10) = citizenshipComboBox.Text
ds.Tables("lecturer").Rows(i).Item(11) = phoneTxt.Text
ds.Tables("lecturer").Rows(i).Item(12) = emailTxt.Text
ds.Tables("lecturer").Rows(i).Item(13) = permitNoTxt.Text
ds.Tables("lecturer").Rows(i).Item(14) = DateTimePicker1.Value
ds.Tables("lecturer").Rows(i).Item(15) = DateTimePicker2.Value
ds.Tables("lecturer").Rows(i).Item(16) = statusComboBox.Text
ds.Tables("lecturer").Rows(i).Item(17) = remark.Text
da.Update(ds, "lecturer")
ds.AcceptChanges()
myConnection.Close()
MsgBox("Record Updated")
Catch ex As Exception
MessageBox.Show(ex.Message & "-" & ex.Source)
End Try
End Using
End Sub
My code is to update the columns and allow user to navigate to the next record.
I'm new to visual basic so detail description and guidance are appreciated. Thanks. In addition, i'm trying to create auto notification system based on the dates. Anyone might enlighten me on which methods or applications to be used in visual basic to do it.

No need to create the update query hand. The CommandBuilder itself generate the necessary instructions to update the database.
Dim ds As New DataSet
Dim da As OleDbDataAdapter
Dim MaxRows As Integer
Dim i As Integer
Dim sql As String
Private Sub updateButton_Click(sender As Object, e As EventArgs) Handles updateButton.Click
Using myConnection = New OleDbConnection("Provider = Microsoft.ACE.OLEDB.12.0; Data Source =C:\LecturerDetail.mdb")
myConnection.Open()
Dim str As String
str = "SELECT * FROM lecturer WHERE ([empId] = #empId)"
Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
cmd.Parameters.AddWithValue("#empId", empIdTxt.Text)
Try
da = new OleDbDataAdapter(cmd)
da.Fill(ds,"lecturer")
ds.Tables("lecturer").Rows(i).Item(0) = empIdTxt.Text
ds.Tables("lecturer").Rows(i).Item(1) = nameTxt.Text
ds.Tables("lecturer").Rows(i).Item(2) = positionComboBox.Text
ds.Tables("lecturer").Rows(i).Item(3) = facultyComboBox.Text
ds.Tables("lecturer").Rows(i).Item(4) = empDeg1.Text
ds.Tables("lecturer").Rows(i).Item(5) = empDeg2.Text
ds.Tables("lecturer").Rows(i).Item(6) = empDeg3.Text
ds.Tables("lecturer").Rows(i).Item(7) = empDeg4.Text
ds.Tables("lecturer").Rows(i).Item(8) = empTypeComboBox.Text
ds.Tables("lecturer").Rows(i).Item(9) = icTxt.Text
ds.Tables("lecturer").Rows(i).Item(10) = citizenshipComboBox.Text
ds.Tables("lecturer").Rows(i).Item(11) = phoneTxt.Text
ds.Tables("lecturer").Rows(i).Item(12) = emailTxt.Text
ds.Tables("lecturer").Rows(i).Item(13) = permitNoTxt.Text
ds.Tables("lecturer").Rows(i).Item(14) = DateTimePicker1.Value
ds.Tables("lecturer").Rows(i).Item(15) = DateTimePicker2.Value
ds.Tables("lecturer").Rows(i).Item(16) = statusComboBox.Text
ds.Tables("lecturer").Rows(i).Item(17) = remark.Text
Dim cb As New OleDb.OleDbCommandBuilder(da)
da.Update(ds, "lecturer")
ds.AcceptChanges()
myConnection.Close()
MsgBox("Record Updated")
Catch ex As Exception
MessageBox.Show(ex.Message & "-" & ex.Source)
End Try
End Using
End Sub

Related

Access Database VB - Searching a database for most 'RECENT' record

I was wondering how I could change the code below, to allow me to search for the most recent record. I am creating a Hotel Booking System and want to use the most recent price in the database but at the moment, it is just searching using the labels which I don't want.
Dim str1 As String
Dim dbpassword As String = "123"
Dim connString As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source= E:\Computing\Hotel Booking System\Database\Hotel Booking System.accdb ;Jet OLEDB:Database Password =" & dbpassword & ";"
Dim MyConn As OleDbConnection
Dim dr As OleDbDataReader
Private Sub Information_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim PriceFound As String = False
MyConn = New OleDbConnection
MyConn.ConnectionString = connString
MyConn.Open()
str1 = ("SELECT * FROM [Prices] WHERE [Adult] = '" & LblPriceAdult.Text & "' AND [Child] = '" & LblPriceChild.Text & "'")
Dim cmd1 As OleDbCommand = New OleDbCommand(str1, MyConn)
dr = cmd1.ExecuteReader
While dr.Read()
PriceFound = True
DateDisplay = dr("ID").ToString
AdultPrice = dr("Adult").ToString
ChildPrice = dr("Child").ToString
SingleRoom = dr("Single").ToString
DoubleRoom = dr("Double").ToString
FamilyRoom = dr("Family").ToString
If PriceFound = True Then
LblPriceAdult.Text = AdultPrice
LblPriceChild.Text = ChildPrice
LblPriceDoubleRoom.Text = DoubleRoom
LblPriceFamilyRoom.Text = FamilyRoom
LblPriceSingleRoom.Text = SingleRoom
End If
End While
MyConn.Close()
End Sub
Based on your previous comments, you need to rewrite your SQL to trap the most recent record.
Try something like this:
SELECT MAX(ID) FROM [Prices] ORDER BY ID DESC
I tried the answer above. However for the code above, it wouldn't search for the most recent so I changed DESC to ASC

Use VB.NET Manipulate Microsoft Access Database

How can I make this work?
Private Sub ListView_MouseClick(sender As Object, e As MouseEventArgs) Handles ListView.MouseClick
conndb = New OleDbConnection
conndb.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Database1.accdb"
Try
conndb.Open()
Dim str As String
str = "Select * FROM customer WHERE CustomerID = '" & ListView.FocusedItem.Text & "'"
COMMAND = New OleDbCommand(str, conndb)
dr = COMMAND.ExecuteReader
If dr.Read = True Then
txtID.Text = dr("CustomerID")
txtFirstName.Text = dr("FirstName")
txtSurname.Text = dr("Surname")
txtAddress.Text = dr("Address")
txtCN1.Text = dr("ContactNo1")
txtCN2.Text = dr("ContactNo2")
txtEmail.Text = dr("EmailAddress")
txtRemarks.Text = dr("Remarks")
txtDebtStatus.Text = dr("DebtStatus")
txtDownPay.Text = dr("DownPayment")
txtDebtBal.Text = dr("DebtBal")
txtCustomerDate.Text = dr("Date")
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
conndb.Dispose()
End Try
End Sub
I need help on how can I make this run without errors, Im using ms access as my database source. There seems to be an error using this code, this code works perfectly fine with mysql but in ms access, it says data mistype error or something like that. Need your help, thanks
Remove the ' surrounding the field CustomerID in your query :
str = "Select * FROM customer WHERE CustomerID = '" & ListView.FocusedItem.Text & "'"
becomes :
str = "Select * FROM customer WHERE CustomerID = " & ListView.FocusedItem.Text
MS Access sees a string when you put an apostrophe, so there is a Type Mismatch Exception, because it is expecting a number...
However, this is a pretty bad idea as Parametrized queries are a better way of doing this (see : Why should I create Parametrized Queries ?)
Also, Use Using
So all in all, it's just another brick in the wall :
Private Sub ListView_MouseClick(sender As Object, e As MouseEventArgs) Handles ListView.MouseClick
Using conndb As New OleDbConnection
conndb.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Database1.accdb"
Try
conndb.Open()
Dim str As String
str = "Select * FROM customer WHERE CustomerID = #Customer"
Using COMMAND As New OleDbCommand(str, conndb)
COMMAND.Parameters.Add("#Customer", SqlDbType.Integer).Value = Integer.Parse(ListView.FocusedItem.Text)
dr = COMMAND.ExecuteReader
If dr.Read = True Then
txtID.Text = dr("CustomerID")
txtFirstName.Text = dr("FirstName")
txtSurname.Text = dr("Surname")
txtAddress.Text = dr("Address")
txtCN1.Text = dr("ContactNo1")
txtCN2.Text = dr("ContactNo2")
txtEmail.Text = dr("EmailAddress")
txtRemarks.Text = dr("Remarks")
txtDebtStatus.Text = dr("DebtStatus")
txtDownPay.Text = dr("DownPayment")
txtDebtBal.Text = dr("DebtBal")
txtCustomerDate.Text = dr("Date")
End If
End Using
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Using
End Sub
Take a look at this sample code that I put together a while back. You can probably learn a lot from this.
Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged, TextBox1.Click
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\your_path\Desktop\Northwind_2012.mdb"
Dim selectCommand As String
Dim connection As New OleDbConnection(connectionString)
'selectCommand = "Select * From MyExcelTable where Fname = '" & TextBox1.Text & "'"
'"SELECT * FROM Customers WHERE Address LIKE '" & strAddressSearch & "%'"
'or ending with:
'"SELECT * FROM Customers WHERE Address LIKE '%" & strAddressSearch & "'"
selectCommand = "Select * From MyExcelTable where Fname Like '" & TextBox1.Text & "%'"
Me.dataAdapter = New OleDbDataAdapter(selectCommand, connection)
With DataGridView1
.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.ColumnHeader
.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.ColumnHeader
End With
Dim commandBuilder As New OleDbCommandBuilder(Me.dataAdapter)
Dim table As New DataTable()
table.Locale = System.Globalization.CultureInfo.InvariantCulture
Me.dataAdapter.Fill(table)
Me.bindingSource1.DataSource = table
Dim data As New DataSet()
data.Locale = System.Globalization.CultureInfo.InvariantCulture
DataGridView1.DataSource = Me.bindingSource1
Me.DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Aqua
Me.DataGridView1.AutoResizeColumns( _
DataGridViewAutoSizeColumnsMode.AllCells)
End Sub

The LEVEL clause includes a reserved word or argument that is misspelled or missing, or the punctuation is incorrect vb.net

Dim connstring As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\Users\vladut.moraru\Desktop\TCO Orders\02_Template_BOM.xls;Extended Properties=""Excel 8.0;HDR=YES;"""
Dim pram As OleDbParameter
Dim dr As DataRow
Dim olecon As OleDbConnection
Dim olecomm As OleDbCommand
Dim olecomm1 As OleDbCommand
Dim oleadpt As OleDbDataAdapter
Dim ds As DataSet
Try
olecon = New OleDbConnection
olecon.ConnectionString = connstring
olecomm = New OleDbCommand
olecomm.CommandText = "Select Level, F_N, Name, Rev from [BOM$]"
olecomm.Connection = olecon
olecomm1 = New OleDbCommand
olecomm1.CommandText = "Insert into [BOM$] " & "(Level, F_N, Name, Rev) values " & "(#FName, #LName, #Age, #Phone)"
olecomm1.Connection = olecon
pram = olecomm1.Parameters.Add("#FName", OleDbType.VarChar)
pram.SourceColumn = "Level"
pram = olecomm1.Parameters.Add("#LName", OleDbType.VarChar)
pram.SourceColumn = "F_N"
pram = olecomm1.Parameters.Add("#Age", OleDbType.VarChar)
pram.SourceColumn = "Name"
pram = olecomm1.Parameters.Add("#Phone", OleDbType.VarChar)
pram.SourceColumn = "Rev"
oleadpt = New OleDbDataAdapter(olecomm)
ds = New DataSet
olecon.Open()
oleadpt.Fill(ds, "BOM")
If IsNothing(ds) = False Then
dr = ds.Tables(0).NewRow
dr("Level") = "Raman"
dr("F_N") = "Tayal"
dr("Name") = 24
dr("Rev") = 98989898
ds.Tables(0).Rows.Add(dr)
oleadpt = New OleDbDataAdapter
oleadpt.InsertCommand = olecomm1
Dim i As Integer = oleadpt.Update(ds, "BOM")
End If
Catch ex As Exception
Finally
olecon.Close()
olecon = Nothing
olecomm = Nothing
oleadpt = Nothing
ds = Nothing
dr = Nothing
pram = Nothing
End Try
I want tot write into tamplate excel with column Level, F_N, Name, Rev and my code generate that error from title. I want to insert some value in my excel but on line oleadpt.Fill(ds, "BOM") give me that error. I put a pic with excel file. The sheet name is BOM
My question is, where i miss to generate that code? I write wrong my columns or my connection?

DataReader Error VB.net and mySql

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim reader As MySqlDataReader
Dim query As String
Dim md As String
md = Me.mskmembdate.Text
md = Me.bday.Text
md = Me.spsbday.Text
Try
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
query = "SELECT * FROM member WHERE (memor = '" & membor.Text & "')"
sqlcom = New MySqlCommand(query, conn)
reader = sqlcom.ExecuteReader
While reader.Read()
Me.lblmembname.Text = reader("membname").ToString
Me.membtype.Text = reader("membtype").ToString
Me.mskmembdate.Text = CDate(reader("membdate")).ToString("MMddyyyy")
Me.lname.Text = reader("lname").ToString
Me.fname.Text = reader("fname").ToString
Me.mname.Text = reader("mname").ToString
Me.nameex.Text = reader("nameex").ToString
Me.bday.Text = CDate(reader("bday")).ToString("MMddyyyy")
Me.membtype.Text = reader("membtype").ToString
Me.spslname.Text = reader("spslname").ToString
Me.spsfname.Text = reader("spsfname").ToString
Me.spsmname.Text = reader("spsmname").ToString
Me.spsbday.Text = CDate(reader("spsbday")).ToString("MMddyyyy")
Me.civil.Text = reader("civil").ToString
Me.sex.Text = reader("sex").ToString
Me.municipal.Text = reader("municipal").ToString
Me.brgy.Text = reader("brgy").ToString
Me.purok.Text = reader("purok").ToString
Me.district.Text = reader("district").ToString
Me.certno.Text = reader("certnumb").ToString
Me.resno.Text = reader("resonumb").ToString
Me.cpno.Text = reader("cpno").ToString
Me.recstat.Text = reader("recstat").ToString
End While
reader.Close()
conn.Dispose()
Catch ex As Exception
End Try
Dim provider As String
Dim dataFile As String
Dim connString As String
Dim myConnection As OleDbConnection = New OleDbConnection
Dim dr As OleDbDataReader
provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="
dataFile = "D:\N.A.C. JR\SAMPLE VB 2008\NewMembership\NewMembership\bin\Debug\profilepic.accdb"
connString = provider & dataFile
myConnection.ConnectionString = connString
myConnection.Open()
Dim str As String
str = "SELECT * FROM info WHERE (memor = '" & membor.Text & "')"
Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
dr = cmd.ExecuteReader()
While dr.Read()
orspspic.Text = dr("spspicture").ToString
orpic.Text = dr("picture").ToString
End While
dr.Close()
myConnection.Close()
varimage = orpic.Text
varimage = orspspic.Text
pic.ImageLocation = orpic.Text
spspic.ImageLocation = orspspic.Text
End Sub
This is my code from frmload i click listview data then form2 opens and sets the data into text boxes but this error pops out "There is already an open DataReader associated with this Connection which must be closed first" ? How can i solve it . Any ideas how to solve this kind of problem?

How to return multiple values from a query vb.net

one question how to store or return multiple queries result values into multiple variables.. I'm using a query that return 4 columns but how to.. individual store those results into 4 separate variables.. here is my code
Private Sub FrmAlumnos_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtCurrentUser.Text = Login.txtUser.Text
Dim strsql As String
strsql = "SELECT ""Agregar"", ""Modificar"", ""Eliminar"", ""Imprimir"" FROM ""Seguridad"".""GrupoPantallas"" WHERE ""IdGrupo"" = (SELECT ""IdGrupo"" FROM ""Seguridad"".""Users"" WHERE ""IdUsers"" = '" _
+ Me.txtCurrentUser.Text + "') AND ""IdPantalla"" = '" + Me.Name + "'"
Try
Using conexion As New Devart.Data.PostgreSql.PgSqlConnection(My.Settings.CNX_Principal)
Dim comando As New Devart.Data.PostgreSql.PgSqlCommand(strsql, conexion)
conexion.Open()
Dim registro As Devart.Data.PostgreSql.PgSqlDataReader = comando.ExecuteReader
If comando.ExecuteReader.Item(0) = 0 Then
btnNew.Visible = False
End If
If comando.ExecuteReader.Item(1) = 0 Then
btnEdit.Visible = False
End If
If comando.ExecuteReader.Item(2) = 0 Then
btnDelete.Visible = False
End If
If comando.ExecuteReader.Item(3) = 0 Then
btnPrint.Visible = False
End If
End Using
Catch ex As Exception
End Try
End Sub
I'm Using PostgreSQL just for you to know...
I think you might find a DataSet to be useful here. Something like:
Dim ds As New DataSet
Dim com As New SqlCommand
com.Connection = <yourconnectionstring>
com.CommandType = CommandType.Text
com.CommandText = "YOURSQLSTUFF"
Dim da As New DataAdapter
da.SelectCommand = com
da.Fill(ds)
ds.Tables(0).TableName = "FirstTable"
ds.Tables(0).PrimaryKey = New DataColumn() {ds.Tables(0).Columns("primaryKeyOfFirstTable")
ds.Tables(1).TableName = "SecondTable"
ds.Tables(1).PrimaryKey = New DataColumn() {ds.Tables(1).Columns("primaryKeyOfSecondTable")
Hope that helps!
-sf
EDIT: After some more searching, I found this link, which might help you out! It's postgreSQL specific!
You need to use the Read method of the DataReader:
Dim strsql As String
strsql = "SELECT ""Agregar"", ""Modificar"", ""Eliminar"", ""Imprimir"" FROM ""Seguridad"".""GrupoPantallas"" WHERE ""IdGrupo"" = (SELECT ""IdGrupo"" FROM ""Seguridad"".""Users"" WHERE ""IdUsers"" = '" _
+ Me.txtCurrentUser.Text + "') AND ""IdPantalla"" = '" + Me.Name + "'"
Try
Using conexion As New Devart.Data.PostgreSql.PgSqlConnection(My.Settings.CNX_Principal)
Dim comando As New Devart.Data.PostgreSql.PgSqlCommand(strsql, conexion)
conexion.Open()
Using registro As Devart.Data.PostgreSql.PgSqlDataReader = comando.ExecuteReader()
//Assuming that there is only a single row returned
If registro.Read()
btnNew.Visible = registro.GetBoolean(0)
btnEdit.Visible = registro.GetBoolean(1)
btnDelete.Visible = registro.GetBoolean(2)
btnPrint.Visible = registro.GetBoolean(3)
End While
End Using
End Using
Catch ex As Exception
End Try
You should also look into using parameters. It would make the code a little cleaner than using a concatenated string and would stop sql injection attacks.
Dim strsql As String
strsql = "SELECT ""Agregar"", ""Modificar"", ""Eliminar"", ""Imprimir"" FROM ""Seguridad"".""GrupoPantallas"" WHERE ""IdGrupo"" = (SELECT ""IdGrupo"" FROM ""Seguridad"".""Users"" WHERE ""IdUsers"" = '" _
+ Me.txtCurrentUser.Text + "') AND ""IdPantalla"" = '" + Me.Name + "'"
Try
Using conexion As New Devart.Data.PostgreSql.PgSqlConnection(My.Settings.CNX_Principal)
Dim comando As New Devart.Data.PostgreSql.PgSqlCommand(strsql, conexion)
conexion.Open()
Dim registro As Devart.Data.PostgreSql.PgSqlDataReader = comando.ExecuteReader
//This is the loop that you missed
While registro.Read()
If comando.ExecuteReader.Item(0) = 0 Then
btnNew.Visible = False
End If
If comando.ExecuteReader.Item(1) = 0 Then
btnEdit.Visible = False
End If
If comando.ExecuteReader.Item(2) = 0 Then
btnDelete.Visible = False
End If
If comando.ExecuteReader.Item(3) = 0 Then
btnPrint.Visible = False
End If
End While
End Using
Catch ex As Exception
End Try
I'm not sure if this is what you're trying to do, but all you have to do is loop through the DataReader as shown above.