Hi can we add column name instead of column number i.e. txtEmpId.Text = empTable.Rows(position)(0).ToString() instead txtEmpId.Text = empTable.Rows(position)(emp_id).ToString() Hemant
This code gives Exception. if you keep clicking previous the index goes negative, and there is no row in the datatable at position -1. Keep clicking next then the index will increase above the maximum nr of rows in datatable. This won't give exceptions because the data adapter keep filling the datatable with extra rows, but still not an elegant solution
first created a function to return a datatable to solve the problem with the accumulating nr of rows in the datatable Public Function getDataTable(connToDBString As String, selectString As String) 'create a connection object, connecting to database Dim conn As New SqlConnection(connToDBString) 'create command object taking the sql select string and connection object as parameter Dim command As New SqlCommand(selectString, conn) 'create a new data adapter passing the command object as parameter Dim adapter As New SqlDataAdapter(command) Dim table As New DataTable 'data adapter fills up the data table with data from database accordeing to select query adapter.Fill(table) Return table End Function
create a databale in the class of the form with navigation buttons Private DT As DataTable i have created the update, add and delete buttons in the form class as well
changed the showData method Public Sub showData(position As Integer, DT As DataTable) Try txtID.Text = DT.Rows(position)(0).ToString txtFirstName.Text = DT.Rows(position)(1).ToString txtLastName.Text = DT.Rows(position)(2).ToString txtHouseNr.Text = DT.Rows(position)(3).ToString txtStreet.Text = DT.Rows(position)(4).ToString Catch ex As Exception MsgBox(ex.Message) End Try End Sub
for the button showing first record and last record: Private Sub btnFirstRecord_Click(sender As Object, e As EventArgs) Handles btnFirstRecord.Click index = 0 showData(index, DT) End Sub Private Sub btnLastRecord_Click(sender As Object, e As EventArgs) Handles btnLastRecord.Click index = DT.Rows.Count - 1 showData(index, DT) End Sub
thanks you teached me this lesson i appreciate that
hello, I followed you and I learned of you
I have a question: if I have a picture field, how to get the image with showData' sub?
Thank you!
Perfect works fine but could you filter records based on a date from a datetimepicker?
Oui c'est vraiment pratique merci beaucoup pour le code
Hi
can we add column name instead of column number i.e.
txtEmpId.Text = empTable.Rows(position)(0).ToString()
instead
txtEmpId.Text = empTable.Rows(position)(emp_id).ToString()
Hemant
Como criar o controlo da data de caducidade de um produto (alguns dias antes) através de uma
mensagem no sql e visual basic?
Thank you so much
there is no row at position 0
indexoutofrenge exception was unhandled
this error show after debug
This code gives Exception. if you keep clicking previous the index goes negative, and there is no row in the datatable at position -1. Keep clicking next then the index will increase above the maximum nr of rows in datatable. This won't give exceptions because the data adapter keep filling the datatable with extra rows, but still not an elegant solution
first created a function to return a datatable to solve the problem with the accumulating nr of rows in the datatable
Public Function getDataTable(connToDBString As String, selectString As String)
'create a connection object, connecting to database
Dim conn As New SqlConnection(connToDBString)
'create command object taking the sql select string and connection object as parameter
Dim command As New SqlCommand(selectString, conn)
'create a new data adapter passing the command object as parameter
Dim adapter As New SqlDataAdapter(command)
Dim table As New DataTable
'data adapter fills up the data table with data from database accordeing to select query
adapter.Fill(table)
Return table
End Function
create a databale in the class of the form with navigation buttons
Private DT As DataTable
i have created the update, add and delete buttons in the form class as well
then in the form load event and in the add, update, delete event
create a new datatable
DT = getDataTable(connString, selectString)
changed the showData method
Public Sub showData(position As Integer, DT As DataTable)
Try
txtID.Text = DT.Rows(position)(0).ToString
txtFirstName.Text = DT.Rows(position)(1).ToString
txtLastName.Text = DT.Rows(position)(2).ToString
txtHouseNr.Text = DT.Rows(position)(3).ToString
txtStreet.Text = DT.Rows(position)(4).ToString
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
for the button showing first record and last record:
Private Sub btnFirstRecord_Click(sender As Object, e As EventArgs) Handles btnFirstRecord.Click
index = 0
showData(index, DT)
End Sub
Private Sub btnLastRecord_Click(sender As Object, e As EventArgs) Handles btnLastRecord.Click
index = DT.Rows.Count - 1
showData(index, DT)
End Sub
Thank YOu
good
thanks sir...
hello sir how to get audio
how to retrive radio button from db
please help sir....