hello to all and thanks for giving all help to newbees,
i have a form in visual basic 2010 with these specification
1 datagridview
7 textboxes
7 comboboxes
2 datepicker
i use a connection with code to ms access.
i am using this code to load data in DGV and also bind the data with code:-
Imports System.Data.OleDb
Imports System.Object
Public Class frmonlineBA_I
Dim myqry As String = Nothing
Dim mycmd As New OleDbCommand
Dim mydr As OleDbDataReader
Dim str As String = Nothing
Private Property IsValidTextboxForNumbers As Boolean
Private lblTbox As New Dictionary(Of TextBox, Label)
Dim CnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\kckdata.accdb"
Dim Con As New OleDbConnection(CnString)
Private dtSource As DataTable = Nothing
Dim DataSet1 As New DataSet
Dim DataSet2 As New DataSet
Dim DataSet3 As New DataSet
Dim DataAdapter1 As OleDbDataAdapter
Dim CMD As New OleDbCommand
Private PageCount As Integer
Private maxRec As Integer
Private pageSize As Integer
Private currentPage As Integer
Private recNo As Integer
Dim sSql As String
Dim ReceiptID As Integer
Dim intSelectedRow As Integer
Private Sub frmonlineBA_I_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.CenterToScreen()
Call connectDatabase()
Call loadsubject()
Call FillDGVadd()
Call FillDGVonline()
'''''''''''data binding clear'''''''''''''''''''
txtadmissionnoBA_I.DataBindings.Clear()
admidatePickerBA_I.DataBindings.Clear()
txtstuname.DataBindings.Clear()
txtfathname.DataBindings.Clear()
txtmothname.DataBindings.Clear()
cmbcategory.DataBindings.Clear()
cmbminority.DataBindings.Clear()
dobPicker1.DataBindings.Clear()
cmbgender.DataBindings.Clear()
txtmobile.DataBindings.Clear()
txtaddress.DataBindings.Clear()
cmbsub1.DataBindings.Clear()
cmbsub2.DataBindings.Clear()
cmbsub3.DataBindings.Clear()
cmbsub4.DataBindings.Clear()
txtsub5.DataBindings.Clear()
'''''''''''''connect data binding'''''''''''''''''''''
txtadmissionnoBA_I.DataBindings.Add("Text", DataSet1, "tbladmissionBA_I.admission_number")
admidatePickerBA_I.DataBindings.Add("Text", DataSet1, "tbladmissionBA_I.admission_date")
txtstuname.DataBindings.Add("Text", DataSet1, "tbladmissionBA_I.students_name")
txtfathname.DataBindings.Add("Text", DataSet1, "tbladmissionBA_I.fathers_name")
txtmothname.DataBindings.Add("Text", DataSet1, "tbladmissionBA_I.mothers_name")
cmbcategory.DataBindings.Add("Text", DataSet1, "tbladmissionBA_I.category")
cmbminority.DataBindings.Add("Text", DataSet1, "tbladmissionBA_I.minority")
dobPicker1.DataBindings.Add("Text", DataSet1, "tbladmissionBA_I.date_of_birth")
cmbgender.DataBindings.Add("Text", DataSet1, "tbladmissionBA_I.gender")
txtmobile.DataBindings.Add("Text", DataSet1, "tbladmissionBA_I.mobile")
txtaddress.DataBindings.Add("Text", DataSet1, "tbladmissionBA_I.address")
cmbsub1.DataBindings.Add("Text", DataSet1, "tbladmissionBA_I.subject_1")
cmbsub2.DataBindings.Add("Text", DataSet1, "tbladmissionBA_I.subject_2")
cmbsub3.DataBindings.Add("Text", DataSet1, "tbladmissionBA_I.subject_3")
cmbsub4.DataBindings.Add("Text", DataSet1, "tbladmissionBA_I.subject_4")
txtsub5.DataBindings.Add("Text", DataSet1, "tbladmissionBA_I.subject_5")
'=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
'''''''''''''''''connect to databinding with online list and online form number'''''''''''''
txtonlineformnoBA_I.DataBindings.Clear()
txtonlineformnoBA_I.DataBindings.Add("Text", DataSet2, "tblonlinedetailBA_I.online_form_number")
'=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=
txtadmissionnoBA_I.Visible = True
CMD.CommandType = CommandType.Text
CMD.Connection = Con
'=-=-=-==-
txtonlineformnoBA_I.Visible = False
btndeletonlineBA_I.Enabled = True
btnsaveonlineBA_I.Enabled = True
btncancel.Enabled = False
btncloseonlineBA_I.Enabled = True
btnaddonlineBA_I.Enabled = True
Call DisconnectDatabase()
End Sub
Private Sub btnsearchadBA_I_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsearchadBA_I.Click
Call connectDatabase()
If txtsearchadBA_I.Text = "" Then
sSql = "SELECT admission_number,admission_date,students_name,fathers_name,mothers_name,category,minority,date_of_birth,gender,mobile,address,subject_1,subject_2,subject_3,subject_4,subject_5 FROM tbladmissionBA_I ORDER BY admission_number"
Else
sSql = "SELECT admission_number,admission_date,students_name,fathers_name,mothers_name,category,minority,date_of_birth,gender,mobile,address,subject_1,subject_2,subject_3,subject_4,subject_5 FROM tbladmissionBA_I WHERE [admission_number] Like '%" & txtsearchadBA_I.Text & "%' OR [admission_date] Like '%" & txtsearchadBA_I.Text & "%' OR [students_name] Like '%" & txtsearchadBA_I.Text & "%' OR [fathers_name] Like '%" & txtsearchadBA_I.Text & "%' OR [mothers_name] Like '%" & txtsearchadBA_I.Text & "%' OR [category] Like '%" & txtsearchadBA_I.Text & "%' OR [minority] Like '%" & txtsearchadBA_I.Text & "%' OR [date_of_birth] Like '%" & txtsearchadBA_I.Text & "%' OR [gender] Like '%" & txtsearchadBA_I.Text & "%' OR [mobile] Like '%" & txtsearchadBA_I.Text & "%' OR [address] Like '%" & txtsearchadBA_I.Text & "%' OR [subject_1] Like '%" & txtsearchadBA_I.Text & "%' OR [subject_2] Like '%" & txtsearchadBA_I.Text & "%' OR [subject_3] Like '%" & txtsearchadBA_I.Text & "%' OR [subject_4] Like '%" & txtsearchadBA_I.Text & "%' OR [subject_5] Like '%" & txtsearchadBA_I.Text & "%' ORDER BY admission_number"
End If
Call LoadDS(sSql)
FillGrid()
Call DisconnectDatabase()
End Sub
Private Sub LoadDS(ByVal sSQL As String)
Try
Dim cnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\kckdata.accdb"
'Open Connection.
Dim conn As OleDbConnection = New OleDbConnection(cnString)
'Set the DataAdapter's query.
DataAdapter1 = New OleDbDataAdapter(sSQL, conn)
DataSet1 = New DataSet()
' Fill the DataSet.
DataAdapter1.Fill(DataSet1, "Items")
' Set the source table.
dtSource = DataSet1.Tables("Items")
'''''''''''data binding clear'''''''''''''''''''
txtadmissionnoBA_I.DataBindings.Clear()
admidatePickerBA_I.DataBindings.Clear()
txtstuname.DataBindings.Clear()
txtfathname.DataBindings.Clear()
txtmothname.DataBindings.Clear()
cmbcategory.DataBindings.Clear()
cmbminority.DataBindings.Clear()
dobPicker1.DataBindings.Clear()
cmbgender.DataBindings.Clear()
txtmobile.DataBindings.Clear()
txtaddress.DataBindings.Clear()
cmbsub1.DataBindings.Clear()
cmbsub2.DataBindings.Clear()
cmbsub3.DataBindings.Clear()
cmbsub4.DataBindings.Clear()
txtsub5.DataBindings.Clear()
'''''''''''''connect data rebinding'''''''''''''''''''''
txtadmissionnoBA_I.DataBindings.Add("Text", DataSet1, "Items.admission_number")
admidatePickerBA_I.DataBindings.Add("Text", DataSet1, "Items.admission_date")
txtstuname.DataBindings.Add("Text", DataSet1, "Items.students_name")
txtfathname.DataBindings.Add("Text", DataSet1, "Items.fathers_name")
txtmothname.DataBindings.Add("Text", DataSet1, "Items.mothers_name")
cmbcategory.DataBindings.Add("Text", DataSet1, "Items.category")
cmbminority.DataBindings.Add("Text", DataSet1, "Items.minority")
dobPicker1.DataBindings.Add("Text", DataSet1, "Items.date_of_birth")
cmbgender.DataBindings.Add("Text", DataSet1, "Items.gender")
txtmobile.DataBindings.Add("Text", DataSet1, "Items.mobile")
txtaddress.DataBindings.Add("Text", DataSet1, "Items.address")
cmbsub1.DataBindings.Add("Text", DataSet1, "Items.subject_1")
cmbsub2.DataBindings.Add("Text", DataSet1, "Items.subject_2")
cmbsub3.DataBindings.Add("Text", DataSet1, "Items.subject_3")
cmbsub4.DataBindings.Add("Text", DataSet1, "Items.subject_4")
txtsub5.DataBindings.Add("Text", DataSet1, "Items.subject_5")
'=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
'=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=
CMD.CommandType = CommandType.Text
CMD.Connection = Con
Catch ex As Exception
MessageBox.Show(ex.Message, "Error...", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub FillGrid()
'Set the start and max records.
pageSize = 20 'txtPageSize.Text
maxRec = dtSource.Rows.Count
PageCount = maxRec \ pageSize
' Adjust the page number if the last page contains a partial page.
If (maxRec Mod pageSize) > 0 Then
PageCount = PageCount + 1
End If
'Initial seeings
currentPage = 1
recNo = 0
' Display the content of the current page.
LoadPage()
End Sub
Private Sub LoadPage()
Dim i As Integer
Dim startRec As Integer
Dim endRec As Integer
Dim dtTemp As DataTable
'Duplicate or clone the source table to create the temporary table.
dtTemp = dtSource.Clone
If currentPage = PageCount Then
endRec = maxRec
Else
endRec = pageSize * currentPage
End If
startRec = recNo
If dtSource.Rows.Count > 0 Then
'Copy the rows from the source table to fill the temporary table.
For i = startRec To endRec - 1
dtTemp.ImportRow(dtSource.Rows(i))
recNo = recNo + 1
Next
End If
DataGridView1.DataSource = dtTemp
End Sub
kindly help me for this because if i search a name like "abc" and the search rows are 3 then only the first row is rebinding other are not binding.
please help for this.