EDN Admin
Well-known member
i have form with textbox and datetimePicker (Master table) , datagridview (Details table) , save and delete button,
what i need is to type in textbox and fill may datetimepicker and datagridview with the releated value from several tables and then manipulate(add/modify/delete) Master and Details tables.
so far i am able to show my data in the winform as i needed excatlly (but i think it is a long way to do that), beside i have problem is to add/modify/delete Master and Details tables.
Note:
i have to works with 5 tables in this form, 1 is the Master table and it should bind to the TNo.text (TNo is PK) and TDate.datetimepicker, and the other tables which it should sho in the datagridview is Details, ANoTable, ANoCTable, Document, Currncies.
(all these tables include Master table have FK with Details table).
i try to solve it by googling it and looking for codes here and there but i fail.
so please help me to optimize my code and make it works fine, i am ready to email you my projet if you want to tak a real view of what i am facing.
thanks in advance.
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Imports System
<span style="color:Blue; Imports System.Data
<span style="color:Blue; Imports System.Data.OleDb
<span style="color:Blue; Imports VB = Microsoft.VisualBasic.Strings
<span style="color:Blue; Public <span style="color:Blue; Class Form3
<span style="color:Blue; Dim con <span style="color:Blue; As OleDbConnection
<span style="color:Blue; Dim myDataSet <span style="color:Blue; As DataSet
<span style="color:Blue; Dim ds <span style="color:Blue; As <span style="color:Blue; New DataSet
<span style="color:Blue; Dim changes <span style="color:Blue; As DataSet
<span style="color:Blue; Dim i <span style="color:Blue; As <span style="color:Blue; Integer
<span style="color:Blue; Dim sql <span style="color:Blue; As <span style="color:Blue; String
<span style="color:Blue; Dim cmd, cmdMaster, cmdDetails, cmdCurrancies, cmdDocument, cmdANoTable, cmdANoCTable <span style="color:Blue; As OleDbCommand
<span style="color:Blue; Dim myDA, daMaster, daDetails, detailsDataAdapter, daCurrancies, daDocument, daANoTable, daANoCTable <span style="color:Blue; As OleDbDataAdapter
<span style="color:Blue; Dim builder, builderMaster, builderDetails, cmdBldCurrancies, cmdBldDocument, cmdBldANoTable, cmdBldANoCTable <span style="color:Blue; As OleDbCommandBuilder
<span style="color:Blue; Dim dTable <span style="color:Blue; As DataTable = <span style="color:Blue; New DataTable
<span style="color:Blue; Dim MasterdTable <span style="color:Blue; As DataTable = <span style="color:Blue; New DataTable
<span style="color:Blue; Dim DetailsdTable <span style="color:Blue; As DataTable = <span style="color:Blue; New DataTable
<span style="color:Blue; Private masterBS <span style="color:Blue; As <span style="color:Blue; New BindingSource()
<span style="color:Blue; Private detailsBS <span style="color:Blue; As <span style="color:Blue; New BindingSource()
<span style="color:Blue; Dim ChkCol <span style="color:Blue; As DataGridViewCheckBoxColumn
<span style="color:Blue; Dim TextCol <span style="color:Blue; As DataGridViewTextBoxColumn
<span style="color:Blue; Dim CmbCol <span style="color:Blue; As DataGridViewComboBoxColumn
<span style="color:Blue; Dim CmbList <span style="color:Blue; As ListBox
<span style="color:Blue; Private <span style="color:Blue; Sub Form1_Disposed(sender <span style="color:Blue; As <span style="color:Blue; Object, e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles <span style="color:Blue; Me.Disposed
con.Close()
con = <span style="color:Blue; Nothing
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub Form1_Load(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles <span style="color:Blue; MyBase.Load
<span style="color:Green; TODO: This line of code loads data into the BooksManagerDataSet.Details table. You can move, or remove it, as needed.
<span style="color:Green; Me.DetailsTableAdapter.Fill(Me.BooksManagerDataSet.Details)
con = <span style="color:Blue; New OleDbConnection(<span style="color:#A31515; "Provider=Microsoft.jet.oledb.4.0;data source=E:BooksManagerBooksManager.mdb")
con.Open()
<span style="color:Blue; Call LastTNo()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub TNo_Enter(<span style="color:Blue; ByVal sender <span style="color:Blue; As <span style="color:Blue; Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles TNo.Enter
<span style="color:Blue; Me.detailsBS.EndEdit()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub LastTNo()
<span style="color:Green; con = New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=E:BooksManagerBooksManager.mdb")
<span style="color:Blue; Try
<span style="color:Green; If con.State = ConnectionState.Closed Then con.Open()
cmd = <span style="color:Blue; New OleDbCommand(<span style="color:#A31515; "SELECT Max(TNo)+1 AS MaxTNo FROM Details WHERE (Left(TNo,6) = " & Format$(Now(), <span style="color:#A31515; "yyMMdd") & <span style="color:#A31515; ")", con)
<span style="color:Blue; Dim Rdr7 <span style="color:Blue; As OleDbDataReader = cmd.ExecuteReader
<span style="color:Blue; If Rdr7.HasRows = <span style="color:Blue; True <span style="color:Blue; Then
<span style="color:Blue; While (Rdr7.Read)
<span style="color:Blue; If IsDBNull(Rdr7.GetValue(0)) = <span style="color:Blue; False <span style="color:Blue; Then
TNo.Text = Rdr7.GetValue(0)
<span style="color:Blue; Else
TNo.Text = Format$(Now(), <span style="color:#A31515; "yyMMdd") & 1
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; While
<span style="color:Blue; Else
TNo.Text = Format$(Now(), <span style="color:#A31515; "yyMMdd") & 1
<span style="color:Blue; End <span style="color:Blue; If
Rdr7.Close()
TNo.Focus()
<span style="color:Green; con.Close()
<span style="color:Green; con = Nothing
<span style="color:Blue; Catch ex <span style="color:Blue; As OleDb.OleDbException
MsgBox(<span style="color:#A31515; "Error Occurred:" & ex.ToString)
<span style="color:Blue; Finally
TDate.Value = Now
<span style="color:Green; If con.State = ConnectionState.Open Then con.Close()
<span style="color:Green; con = Nothing
<span style="color:Blue; End <span style="color:Blue; Try
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub CmdSave_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles CmdSave.Click
<span style="color:Blue; Me.Validate()
<span style="color:Blue; Me.masterBS.EndEdit()
<span style="color:Blue; Me.daMaster.Update(myDataSet.Tables(<span style="color:#A31515; "Master"))
<span style="color:Green; Me.myDataSet.AcceptChanges()
<span style="color:Blue; Me.detailsBS.EndEdit()
<span style="color:Blue; Me.daDetails.Update(<span style="color:Blue; Me.myDataSet, <span style="color:#A31515; "Details")
<span style="color:Blue; Me.myDataSet.AcceptChanges()
<span style="color:Green; Me.masterBS.EndEdit()
<span style="color:Green; Me.daMaster.Update(Me.myDataSet, "Master")
<span style="color:Green; Me.detailsBS.EndEdit()
<span style="color:Green; Me.daDetails.Update(Me.myDataSet, "Details")
<span style="color:Green; Try
<span style="color:Green; builderMaster = New OleDbCommandBuilder(daMaster)
<span style="color:Green; Me.masterBS.EndEdit()
<span style="color:Green; changes = myDataSet.GetChanges()
<span style="color:Green; If changes IsNot Nothing Then
<span style="color:Green; daMaster.Update(myDataSet.Tables(0))
<span style="color:Green; End If
<span style="color:Green; myDataSet.AcceptChanges()
<span style="color:Green; Try
<span style="color:Green; builderDetails = New OleDbCommandBuilder(daDetails)
<span style="color:Green; Me.detailsBS.EndEdit()
<span style="color:Green; changes = myDataSet.GetChanges()
<span style="color:Green; If changes IsNot Nothing Then
<span style="color:Green; daDetails.Update(myDataSet.Tables(1))
<span style="color:Green; End If
<span style="color:Green; myDataSet.AcceptChanges()
<span style="color:Green; MsgBox("Save changes")
<span style="color:Green; Catch ex As Exception
<span style="color:Green; MsgBox(ex.ToString)
<span style="color:Green; End Try
<span style="color:Green; Catch ex As Exception
<span style="color:Green; MsgBox(ex.ToString)
<span style="color:Green; End Try
<span style="color:Blue; Call LastTNo()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub TNo_TextChanged(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles TNo.TextChanged
<span style="color:Blue; On <span style="color:Blue; Error <span style="color:Blue; Resume <span style="color:Blue; Next
<span style="color:Blue; If TNo.TextLength < 7 <span style="color:Blue; Then <span style="color:Blue; Exit <span style="color:Blue; Sub
<span style="color:Blue; If VB.Right(TNo.Text, TNo.TextLength - 6) < 1 <span style="color:Blue; Then <span style="color:Blue; Exit <span style="color:Blue; Sub
<span style="color:Green; If con.State = ConnectionState.Closed Then con.Open()
<span style="color:Blue; Dim cmdMaster <span style="color:Blue; As OleDbCommand = <span style="color:Blue; New OleDbCommand(<span style="color:#A31515; "Select * FROM Master WHERE TNo Like %" & TNo.Text & <span style="color:#A31515; "%", con)
daMaster = <span style="color:Blue; New OleDbDataAdapter(cmdMaster)
<span style="color:Green; Automatically generates DeleteCommand,UpdateCommand and InsertCommand for DataAdapter object
<span style="color:Blue; Dim builderMaster <span style="color:Blue; As OleDbCommandBuilder = <span style="color:Blue; New OleDbCommandBuilder(daMaster)
myDataSet = <span style="color:Blue; New DataSet()
daMaster.Fill(myDataSet, <span style="color:#A31515; "Master")
TNo.DataBindings.Clear()
TDate.DataBindings.Clear()
TNo.DataBindings.Add(<span style="color:#A31515; "Text", myDataSet.Tables(<span style="color:#A31515; "Master").DefaultView, <span style="color:#A31515; "TNo") <span style="color:Green; , True)
TDate.DataBindings.Add(<span style="color:#A31515; "Value", myDataSet.Tables(<span style="color:#A31515; "Master").DefaultView, <span style="color:#A31515; "TDate") <span style="color:Green; , True)
<span style="color:Green; masterBS.DataSource = myDataSet
<span style="color:Green; masterBS.DataMember = "MasterB"
<span style="color:Green; Clear any previous bindings...
DataGridView1.Columns.Clear()
DataGridView1.DataSource = <span style="color:Blue; Nothing
<span style="color:Green; cmdDetails = New OleDbCommand("Select * FROM Details WHERE TNo Like %" & TNo.Text & "%", con)
<span style="color:Green; daDetails = New OleDbDataAdapter(cmdDetails)
<span style="color:Green; dTable = New DataTable
<span style="color:Green; Automatically generates DeleteCommand,UpdateCommand and InsertCommand for DataAdapter object
<span style="color:Green; builderDetails = New OleDbCommandBuilder(daDetails)
<span style="color:Green; myDataSet = New DataSet()
<span style="color:Green; daDetails.Fill(dTable)
<span style="color:Green; daDetails.Fill(myDataSet, "Details")
<span style="color:Green; DataGridView1.DataSource = myDataSet.Tables("Details").DefaultView
<span style="color:Green; detailsBS.DataSource = myDataSet
<span style="color:Green; detailsBS.DataMember = "Details"
<span style="color:Blue; Dim cmdDetails <span style="color:Blue; As OleDbCommand = <span style="color:Blue; New OleDbCommand(<span style="color:#A31515; "Select * FROM Details WHERE TNo Like %" & TNo.Text & <span style="color:#A31515; "%", con)
daDetails = <span style="color:Blue; New OleDbDataAdapter(cmdDetails)
<span style="color:Blue; Dim builderDetails <span style="color:Blue; As OleDbCommandBuilder = <span style="color:Blue; New OleDbCommandBuilder(daDetails)
myDataSet = <span style="color:Blue; New DataSet()
daDetails.Fill(myDataSet, <span style="color:#A31515; "Details")
DataGridView1.DataSource = myDataSet.Tables(<span style="color:#A31515; "Details").DefaultView
DataGridView1.DataMember = <span style="color:#A31515; "Details"
detailsBS.DataSource = myDataSet
detailsBS.DataMember = <span style="color:#A31515; "Details"
<span style="color:Green; Dim drMyRelation As New DataRelation("myDataSet", myDataSet.Tables("Master").Columns("TNo"), myDataSet.Tables("Details").Columns("TNo"))
<span style="color:Green; myDataSet.Relations.Add(drMyRelation)
<span style="color:Green; ---------------------------------------------------------------------------------------------------------
<span style="color:Green; Remove the auto-generated columns
DataGridView1.Columns.Remove(<span style="color:#A31515; "ANo")
DataGridView1.Columns.Remove(<span style="color:#A31515; "Debit")
DataGridView1.Columns.Remove(<span style="color:#A31515; "Credit")
DataGridView1.Columns.Remove(<span style="color:#A31515; "CurID")
DataGridView1.Columns.Remove(<span style="color:#A31515; "CurRate")
DataGridView1.Columns.Remove(<span style="color:#A31515; "DocNo")
DataGridView1.Columns.Remove(<span style="color:#A31515; "DocDetail")
DataGridView1.Columns.Remove(<span style="color:#A31515; "ANoC")
DataGridView1.Columns.Remove(<span style="color:#A31515; "Info")
DataGridView1.Columns.Item(<span style="color:#A31515; "TNo").Visible = <span style="color:Blue; False
<span style="color:Green; Dim col As New DataGridViewComboBoxColumn
<span style="color:Green; Me.DataGridView1.Columns.Add(col)
<span style="color:Green; Me.DataGridView1.RowCount = 5
<span style="color:Green; Dim row As DataGridViewRow
<span style="color:Green; For Each row In Me.DataGridView1.Rows
<span style="color:Green; row.Cells(0).Value = DateTime.Now
<span style="color:Green; Next row
cmdANoTable = <span style="color:Blue; New OleDbCommand(<span style="color:#A31515; "SELECT ANo, ANo+ : +ANoName as ANoName FROM(ANoTable) WHERE (ANoTable.AType = 1) AND (ANoTable.AActive = 0) ORDER BY ANoTable.ANo", con)
daANoTable = <span style="color:Blue; New OleDbDataAdapter(cmdANoTable)
cmdBldANoTable = <span style="color:Blue; New OleDbCommandBuilder(daANoTable)
daANoTable.Fill(myDataSet, <span style="color:#A31515; "ANoTable")
CmbCol = <span style="color:Blue; New DataGridViewComboBoxColumn()
CmbCol.HeaderText = <span style="color:#A31515; "ANo "
<span style="color:Green; CmbCol.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing
CmbCol.DataPropertyName = <span style="color:#A31515; "ANo"
CmbCol.DataSource = myDataSet.Tables(<span style="color:#A31515; "ANoTable")
CmbCol.DisplayMember = <span style="color:#A31515; "ANoName"
CmbCol.ValueMember = <span style="color:#A31515; "ANo"
CmbCol.AutoComplete = <span style="color:Blue; True
CmbCol.Width = 250
DataGridView1.Columns.Add(CmbCol)
cmdCurrancies = <span style="color:Blue; New OleDbCommand(<span style="color:#A31515; "SELECT Currancies.* FROM(Currancies) ORDER BY Currancies.CurDef DESC", con)
daCurrancies = <span style="color:Blue; New OleDbDataAdapter(cmdCurrancies)
cmdBldCurrancies = <span style="color:Blue; New OleDbCommandBuilder(daCurrancies)
<span style="color:Green; myDataSet = New DataSet()
daCurrancies.Fill(myDataSet, <span style="color:#A31515; "Currancies")
CmbCol = <span style="color:Blue; New DataGridViewComboBoxColumn()
CmbCol.HeaderText = <span style="color:#A31515; "Currancy"
<span style="color:Green; CmbCol.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing
CmbCol.DataPropertyName = <span style="color:#A31515; "CurID"
CmbCol.DataSource = myDataSet.Tables(<span style="color:#A31515; "Currancies")
CmbCol.DisplayMember = <span style="color:#A31515; "CurName"
CmbCol.ValueMember = <span style="color:#A31515; "CurID"
CmbCol.Width = 100
DataGridView1.Columns.Add(CmbCol)
<span style="color:Green; TextCol = New DataGridViewTextBoxColumn()
<span style="color:Green; TextCol.HeaderText = "CurRate"
<span style="color:Green; TextCol.DataPropertyName = myDataSet.Tables("Details").Columns("CurRate").ToString
<span style="color:Green; TextCol.ReadOnly = True
<span style="color:Green; TextCol.Width = 80
<span style="color:Green; TextCol.Resizable = DataGridViewTriState.True
<span style="color:Green; DataGridView1.Columns.Add(TextCol)
<span style="color:Green; DataGridView1.Columns.Item("CurRate").Visible = False
TextCol = <span style="color:Blue; New DataGridViewTextBoxColumn()
TextCol.HeaderText = <span style="color:#A31515; "Credit"
TextCol.DataPropertyName = myDataSet.Tables(<span style="color:#A31515; "Details").Columns(<span style="color:#A31515; "Credit").ToString
<span style="color:Green; TextCol.ReadOnly = True
TextCol.Width = 100
TextCol.Resizable = DataGridViewTriState.<span style="color:Blue; True
DataGridView1.Columns.Add(TextCol)
TextCol = <span style="color:Blue; New DataGridViewTextBoxColumn()
TextCol.HeaderText = <span style="color:#A31515; "Debit"
TextCol.DataPropertyName = myDataSet.Tables(<span style="color:#A31515; "Details").Columns(<span style="color:#A31515; "Debit").ToString
<span style="color:Green; TextCol.ReadOnly = True
TextCol.Width = 100
TextCol.Resizable = DataGridViewTriState.<span style="color:Blue; True
DataGridView1.Columns.Add(TextCol)
DataGridView1.Columns.Remove(<span style="color:#A31515; "DocNo")
cmdDocument = <span style="color:Blue; New OleDbCommand(<span style="color:#A31515; "SELECT Document.* FROM(Document) ORDER BY Document.DocNo", con)
daDocument = <span style="color:Blue; New OleDbDataAdapter(cmdDocument)
cmdBldDocument = <span style="color:Blue; New OleDbCommandBuilder(daDocument)
daDocument.Fill(myDataSet, <span style="color:#A31515; "Document")
CmbCol = <span style="color:Blue; New DataGridViewComboBoxColumn()
CmbCol.HeaderText = <span style="color:#A31515; "Document"
<span style="color:Green; CmbCol.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing
CmbCol.DataPropertyName = <span style="color:#A31515; "DocNo"
CmbCol.DataSource = myDataSet.Tables(<span style="color:#A31515; "Document")
CmbCol.DisplayMember = <span style="color:#A31515; "DocName"
CmbCol.ValueMember = <span style="color:#A31515; "DocNo"
CmbCol.Width = 100
DataGridView1.Columns.Add(CmbCol)
DataGridView1.Columns.Remove(<span style="color:#A31515; "ANoC")
cmdANoCTable = <span style="color:Blue; New OleDbCommand(<span style="color:#A31515; "SELECT ANoCTable.* FROM(ANoCTable) ORDER BY ANoCTable.ANoC", con)
daANoCTable = <span style="color:Blue; New OleDbDataAdapter(cmdANoCTable)
cmdBldANoCTable = <span style="color:Blue; New OleDbCommandBuilder(daANoCTable)
daANoCTable.Fill(myDataSet, <span style="color:#A31515; "ANoCTable")
CmbCol = <span style="color:Blue; New DataGridViewComboBoxColumn()
CmbCol.HeaderText = <span style="color:#A31515; "ANoCTable"
<span style="color:Green; CmbCol.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing
CmbCol.DataPropertyName = <span style="color:#A31515; "ANoC"
CmbCol.DataSource = myDataSet.Tables(<span style="color:#A31515; "ANoCTable")
CmbCol.DisplayMember = <span style="color:#A31515; "ANoNameC"
CmbCol.ValueMember = <span style="color:#A31515; "ANoC"
CmbCol.Width = 100
DataGridView1.Columns.Add(CmbCol)
TextCol = <span style="color:Blue; New DataGridViewTextBoxColumn()
TextCol.HeaderText = <span style="color:#A31515; "Info"
TextCol.DataPropertyName = myDataSet.Tables(<span style="color:#A31515; "Details").Columns(<span style="color:#A31515; "Info").ToString
<span style="color:Green; TextCol.ReadOnly = True
TextCol.Width = 205
TextCol.Resizable = DataGridViewTriState.<span style="color:Blue; True
DataGridView1.Columns.Add(TextCol)
DataGridView1.Columns.Item(<span style="color:#A31515; "Info").Visible = <span style="color:Blue; False
<span style="color:Green; con.Close()
<span style="color:Green; con = Nothing
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub DataGridView1_Enter(<span style="color:Blue; ByVal sender <span style="color:Blue; As <span style="color:Blue; Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles DataGridView1.Enter
<span style="color:Blue; Me.masterBS.EndEdit()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub TDate_Enter(<span style="color:Blue; ByVal sender <span style="color:Blue; As <span style="color:Blue; Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles TDate.Enter
<span style="color:Blue; Me.detailsBS.EndEdit()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub CmdDel_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles CmdDel.Click
<span style="color:Blue; Dim SQLDelete <span style="color:Blue; As <span style="color:Blue; String = <span style="color:#A31515; "DELETE FROM Master WHERE TNo = " & TNo.Text
con = <span style="color:Blue; New OleDbConnection(<span style="color:#A31515; "Provider=Microsoft.jet.oledb.4.0;data source=E:BooksManagerBooksManager.mdb")
con.Open()
cmd = <span style="color:Blue; New OleDbCommand(<span style="color:#A31515; "DELETE FROM Master WHERE TNo = " & TNo.Text, con)
<span style="color:Blue; Try
con.Open()
cmd.ExecuteNonQuery()
<span style="color:Blue; Call LastTNo()
<span style="color:Blue; Catch ex <span style="color:Blue; As OleDb.OleDbException
MsgBox(<span style="color:#A31515; "Error Occurred:" & ex.ToString)
<span style="color:Blue; Finally
con.Close()
<span style="color:Green; If con.State = ConnectionState.Open Then con.Close()
<span style="color:Blue; End <span style="color:Blue; Try
<span style="color:Blue; Call LastTNo()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub CmdRefresh_Click(sender <span style="color:Blue; As System.Object, e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles CmdRefresh.Click
<span style="color:Blue; Call LastTNo()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; End <span style="color:Blue; Class<br/><br/>
[/code]
<hr class="sig Wire & Wireless Network Engineer
View the full article
what i need is to type in textbox and fill may datetimepicker and datagridview with the releated value from several tables and then manipulate(add/modify/delete) Master and Details tables.
so far i am able to show my data in the winform as i needed excatlly (but i think it is a long way to do that), beside i have problem is to add/modify/delete Master and Details tables.
Note:
i have to works with 5 tables in this form, 1 is the Master table and it should bind to the TNo.text (TNo is PK) and TDate.datetimepicker, and the other tables which it should sho in the datagridview is Details, ANoTable, ANoCTable, Document, Currncies.
(all these tables include Master table have FK with Details table).
i try to solve it by googling it and looking for codes here and there but i fail.
so please help me to optimize my code and make it works fine, i am ready to email you my projet if you want to tak a real view of what i am facing.
thanks in advance.
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Imports System
<span style="color:Blue; Imports System.Data
<span style="color:Blue; Imports System.Data.OleDb
<span style="color:Blue; Imports VB = Microsoft.VisualBasic.Strings
<span style="color:Blue; Public <span style="color:Blue; Class Form3
<span style="color:Blue; Dim con <span style="color:Blue; As OleDbConnection
<span style="color:Blue; Dim myDataSet <span style="color:Blue; As DataSet
<span style="color:Blue; Dim ds <span style="color:Blue; As <span style="color:Blue; New DataSet
<span style="color:Blue; Dim changes <span style="color:Blue; As DataSet
<span style="color:Blue; Dim i <span style="color:Blue; As <span style="color:Blue; Integer
<span style="color:Blue; Dim sql <span style="color:Blue; As <span style="color:Blue; String
<span style="color:Blue; Dim cmd, cmdMaster, cmdDetails, cmdCurrancies, cmdDocument, cmdANoTable, cmdANoCTable <span style="color:Blue; As OleDbCommand
<span style="color:Blue; Dim myDA, daMaster, daDetails, detailsDataAdapter, daCurrancies, daDocument, daANoTable, daANoCTable <span style="color:Blue; As OleDbDataAdapter
<span style="color:Blue; Dim builder, builderMaster, builderDetails, cmdBldCurrancies, cmdBldDocument, cmdBldANoTable, cmdBldANoCTable <span style="color:Blue; As OleDbCommandBuilder
<span style="color:Blue; Dim dTable <span style="color:Blue; As DataTable = <span style="color:Blue; New DataTable
<span style="color:Blue; Dim MasterdTable <span style="color:Blue; As DataTable = <span style="color:Blue; New DataTable
<span style="color:Blue; Dim DetailsdTable <span style="color:Blue; As DataTable = <span style="color:Blue; New DataTable
<span style="color:Blue; Private masterBS <span style="color:Blue; As <span style="color:Blue; New BindingSource()
<span style="color:Blue; Private detailsBS <span style="color:Blue; As <span style="color:Blue; New BindingSource()
<span style="color:Blue; Dim ChkCol <span style="color:Blue; As DataGridViewCheckBoxColumn
<span style="color:Blue; Dim TextCol <span style="color:Blue; As DataGridViewTextBoxColumn
<span style="color:Blue; Dim CmbCol <span style="color:Blue; As DataGridViewComboBoxColumn
<span style="color:Blue; Dim CmbList <span style="color:Blue; As ListBox
<span style="color:Blue; Private <span style="color:Blue; Sub Form1_Disposed(sender <span style="color:Blue; As <span style="color:Blue; Object, e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles <span style="color:Blue; Me.Disposed
con.Close()
con = <span style="color:Blue; Nothing
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub Form1_Load(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles <span style="color:Blue; MyBase.Load
<span style="color:Green; TODO: This line of code loads data into the BooksManagerDataSet.Details table. You can move, or remove it, as needed.
<span style="color:Green; Me.DetailsTableAdapter.Fill(Me.BooksManagerDataSet.Details)
con = <span style="color:Blue; New OleDbConnection(<span style="color:#A31515; "Provider=Microsoft.jet.oledb.4.0;data source=E:BooksManagerBooksManager.mdb")
con.Open()
<span style="color:Blue; Call LastTNo()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub TNo_Enter(<span style="color:Blue; ByVal sender <span style="color:Blue; As <span style="color:Blue; Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles TNo.Enter
<span style="color:Blue; Me.detailsBS.EndEdit()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub LastTNo()
<span style="color:Green; con = New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=E:BooksManagerBooksManager.mdb")
<span style="color:Blue; Try
<span style="color:Green; If con.State = ConnectionState.Closed Then con.Open()
cmd = <span style="color:Blue; New OleDbCommand(<span style="color:#A31515; "SELECT Max(TNo)+1 AS MaxTNo FROM Details WHERE (Left(TNo,6) = " & Format$(Now(), <span style="color:#A31515; "yyMMdd") & <span style="color:#A31515; ")", con)
<span style="color:Blue; Dim Rdr7 <span style="color:Blue; As OleDbDataReader = cmd.ExecuteReader
<span style="color:Blue; If Rdr7.HasRows = <span style="color:Blue; True <span style="color:Blue; Then
<span style="color:Blue; While (Rdr7.Read)
<span style="color:Blue; If IsDBNull(Rdr7.GetValue(0)) = <span style="color:Blue; False <span style="color:Blue; Then
TNo.Text = Rdr7.GetValue(0)
<span style="color:Blue; Else
TNo.Text = Format$(Now(), <span style="color:#A31515; "yyMMdd") & 1
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; While
<span style="color:Blue; Else
TNo.Text = Format$(Now(), <span style="color:#A31515; "yyMMdd") & 1
<span style="color:Blue; End <span style="color:Blue; If
Rdr7.Close()
TNo.Focus()
<span style="color:Green; con.Close()
<span style="color:Green; con = Nothing
<span style="color:Blue; Catch ex <span style="color:Blue; As OleDb.OleDbException
MsgBox(<span style="color:#A31515; "Error Occurred:" & ex.ToString)
<span style="color:Blue; Finally
TDate.Value = Now
<span style="color:Green; If con.State = ConnectionState.Open Then con.Close()
<span style="color:Green; con = Nothing
<span style="color:Blue; End <span style="color:Blue; Try
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub CmdSave_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles CmdSave.Click
<span style="color:Blue; Me.Validate()
<span style="color:Blue; Me.masterBS.EndEdit()
<span style="color:Blue; Me.daMaster.Update(myDataSet.Tables(<span style="color:#A31515; "Master"))
<span style="color:Green; Me.myDataSet.AcceptChanges()
<span style="color:Blue; Me.detailsBS.EndEdit()
<span style="color:Blue; Me.daDetails.Update(<span style="color:Blue; Me.myDataSet, <span style="color:#A31515; "Details")
<span style="color:Blue; Me.myDataSet.AcceptChanges()
<span style="color:Green; Me.masterBS.EndEdit()
<span style="color:Green; Me.daMaster.Update(Me.myDataSet, "Master")
<span style="color:Green; Me.detailsBS.EndEdit()
<span style="color:Green; Me.daDetails.Update(Me.myDataSet, "Details")
<span style="color:Green; Try
<span style="color:Green; builderMaster = New OleDbCommandBuilder(daMaster)
<span style="color:Green; Me.masterBS.EndEdit()
<span style="color:Green; changes = myDataSet.GetChanges()
<span style="color:Green; If changes IsNot Nothing Then
<span style="color:Green; daMaster.Update(myDataSet.Tables(0))
<span style="color:Green; End If
<span style="color:Green; myDataSet.AcceptChanges()
<span style="color:Green; Try
<span style="color:Green; builderDetails = New OleDbCommandBuilder(daDetails)
<span style="color:Green; Me.detailsBS.EndEdit()
<span style="color:Green; changes = myDataSet.GetChanges()
<span style="color:Green; If changes IsNot Nothing Then
<span style="color:Green; daDetails.Update(myDataSet.Tables(1))
<span style="color:Green; End If
<span style="color:Green; myDataSet.AcceptChanges()
<span style="color:Green; MsgBox("Save changes")
<span style="color:Green; Catch ex As Exception
<span style="color:Green; MsgBox(ex.ToString)
<span style="color:Green; End Try
<span style="color:Green; Catch ex As Exception
<span style="color:Green; MsgBox(ex.ToString)
<span style="color:Green; End Try
<span style="color:Blue; Call LastTNo()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub TNo_TextChanged(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles TNo.TextChanged
<span style="color:Blue; On <span style="color:Blue; Error <span style="color:Blue; Resume <span style="color:Blue; Next
<span style="color:Blue; If TNo.TextLength < 7 <span style="color:Blue; Then <span style="color:Blue; Exit <span style="color:Blue; Sub
<span style="color:Blue; If VB.Right(TNo.Text, TNo.TextLength - 6) < 1 <span style="color:Blue; Then <span style="color:Blue; Exit <span style="color:Blue; Sub
<span style="color:Green; If con.State = ConnectionState.Closed Then con.Open()
<span style="color:Blue; Dim cmdMaster <span style="color:Blue; As OleDbCommand = <span style="color:Blue; New OleDbCommand(<span style="color:#A31515; "Select * FROM Master WHERE TNo Like %" & TNo.Text & <span style="color:#A31515; "%", con)
daMaster = <span style="color:Blue; New OleDbDataAdapter(cmdMaster)
<span style="color:Green; Automatically generates DeleteCommand,UpdateCommand and InsertCommand for DataAdapter object
<span style="color:Blue; Dim builderMaster <span style="color:Blue; As OleDbCommandBuilder = <span style="color:Blue; New OleDbCommandBuilder(daMaster)
myDataSet = <span style="color:Blue; New DataSet()
daMaster.Fill(myDataSet, <span style="color:#A31515; "Master")
TNo.DataBindings.Clear()
TDate.DataBindings.Clear()
TNo.DataBindings.Add(<span style="color:#A31515; "Text", myDataSet.Tables(<span style="color:#A31515; "Master").DefaultView, <span style="color:#A31515; "TNo") <span style="color:Green; , True)
TDate.DataBindings.Add(<span style="color:#A31515; "Value", myDataSet.Tables(<span style="color:#A31515; "Master").DefaultView, <span style="color:#A31515; "TDate") <span style="color:Green; , True)
<span style="color:Green; masterBS.DataSource = myDataSet
<span style="color:Green; masterBS.DataMember = "MasterB"
<span style="color:Green; Clear any previous bindings...
DataGridView1.Columns.Clear()
DataGridView1.DataSource = <span style="color:Blue; Nothing
<span style="color:Green; cmdDetails = New OleDbCommand("Select * FROM Details WHERE TNo Like %" & TNo.Text & "%", con)
<span style="color:Green; daDetails = New OleDbDataAdapter(cmdDetails)
<span style="color:Green; dTable = New DataTable
<span style="color:Green; Automatically generates DeleteCommand,UpdateCommand and InsertCommand for DataAdapter object
<span style="color:Green; builderDetails = New OleDbCommandBuilder(daDetails)
<span style="color:Green; myDataSet = New DataSet()
<span style="color:Green; daDetails.Fill(dTable)
<span style="color:Green; daDetails.Fill(myDataSet, "Details")
<span style="color:Green; DataGridView1.DataSource = myDataSet.Tables("Details").DefaultView
<span style="color:Green; detailsBS.DataSource = myDataSet
<span style="color:Green; detailsBS.DataMember = "Details"
<span style="color:Blue; Dim cmdDetails <span style="color:Blue; As OleDbCommand = <span style="color:Blue; New OleDbCommand(<span style="color:#A31515; "Select * FROM Details WHERE TNo Like %" & TNo.Text & <span style="color:#A31515; "%", con)
daDetails = <span style="color:Blue; New OleDbDataAdapter(cmdDetails)
<span style="color:Blue; Dim builderDetails <span style="color:Blue; As OleDbCommandBuilder = <span style="color:Blue; New OleDbCommandBuilder(daDetails)
myDataSet = <span style="color:Blue; New DataSet()
daDetails.Fill(myDataSet, <span style="color:#A31515; "Details")
DataGridView1.DataSource = myDataSet.Tables(<span style="color:#A31515; "Details").DefaultView
DataGridView1.DataMember = <span style="color:#A31515; "Details"
detailsBS.DataSource = myDataSet
detailsBS.DataMember = <span style="color:#A31515; "Details"
<span style="color:Green; Dim drMyRelation As New DataRelation("myDataSet", myDataSet.Tables("Master").Columns("TNo"), myDataSet.Tables("Details").Columns("TNo"))
<span style="color:Green; myDataSet.Relations.Add(drMyRelation)
<span style="color:Green; ---------------------------------------------------------------------------------------------------------
<span style="color:Green; Remove the auto-generated columns
DataGridView1.Columns.Remove(<span style="color:#A31515; "ANo")
DataGridView1.Columns.Remove(<span style="color:#A31515; "Debit")
DataGridView1.Columns.Remove(<span style="color:#A31515; "Credit")
DataGridView1.Columns.Remove(<span style="color:#A31515; "CurID")
DataGridView1.Columns.Remove(<span style="color:#A31515; "CurRate")
DataGridView1.Columns.Remove(<span style="color:#A31515; "DocNo")
DataGridView1.Columns.Remove(<span style="color:#A31515; "DocDetail")
DataGridView1.Columns.Remove(<span style="color:#A31515; "ANoC")
DataGridView1.Columns.Remove(<span style="color:#A31515; "Info")
DataGridView1.Columns.Item(<span style="color:#A31515; "TNo").Visible = <span style="color:Blue; False
<span style="color:Green; Dim col As New DataGridViewComboBoxColumn
<span style="color:Green; Me.DataGridView1.Columns.Add(col)
<span style="color:Green; Me.DataGridView1.RowCount = 5
<span style="color:Green; Dim row As DataGridViewRow
<span style="color:Green; For Each row In Me.DataGridView1.Rows
<span style="color:Green; row.Cells(0).Value = DateTime.Now
<span style="color:Green; Next row
cmdANoTable = <span style="color:Blue; New OleDbCommand(<span style="color:#A31515; "SELECT ANo, ANo+ : +ANoName as ANoName FROM(ANoTable) WHERE (ANoTable.AType = 1) AND (ANoTable.AActive = 0) ORDER BY ANoTable.ANo", con)
daANoTable = <span style="color:Blue; New OleDbDataAdapter(cmdANoTable)
cmdBldANoTable = <span style="color:Blue; New OleDbCommandBuilder(daANoTable)
daANoTable.Fill(myDataSet, <span style="color:#A31515; "ANoTable")
CmbCol = <span style="color:Blue; New DataGridViewComboBoxColumn()
CmbCol.HeaderText = <span style="color:#A31515; "ANo "
<span style="color:Green; CmbCol.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing
CmbCol.DataPropertyName = <span style="color:#A31515; "ANo"
CmbCol.DataSource = myDataSet.Tables(<span style="color:#A31515; "ANoTable")
CmbCol.DisplayMember = <span style="color:#A31515; "ANoName"
CmbCol.ValueMember = <span style="color:#A31515; "ANo"
CmbCol.AutoComplete = <span style="color:Blue; True
CmbCol.Width = 250
DataGridView1.Columns.Add(CmbCol)
cmdCurrancies = <span style="color:Blue; New OleDbCommand(<span style="color:#A31515; "SELECT Currancies.* FROM(Currancies) ORDER BY Currancies.CurDef DESC", con)
daCurrancies = <span style="color:Blue; New OleDbDataAdapter(cmdCurrancies)
cmdBldCurrancies = <span style="color:Blue; New OleDbCommandBuilder(daCurrancies)
<span style="color:Green; myDataSet = New DataSet()
daCurrancies.Fill(myDataSet, <span style="color:#A31515; "Currancies")
CmbCol = <span style="color:Blue; New DataGridViewComboBoxColumn()
CmbCol.HeaderText = <span style="color:#A31515; "Currancy"
<span style="color:Green; CmbCol.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing
CmbCol.DataPropertyName = <span style="color:#A31515; "CurID"
CmbCol.DataSource = myDataSet.Tables(<span style="color:#A31515; "Currancies")
CmbCol.DisplayMember = <span style="color:#A31515; "CurName"
CmbCol.ValueMember = <span style="color:#A31515; "CurID"
CmbCol.Width = 100
DataGridView1.Columns.Add(CmbCol)
<span style="color:Green; TextCol = New DataGridViewTextBoxColumn()
<span style="color:Green; TextCol.HeaderText = "CurRate"
<span style="color:Green; TextCol.DataPropertyName = myDataSet.Tables("Details").Columns("CurRate").ToString
<span style="color:Green; TextCol.ReadOnly = True
<span style="color:Green; TextCol.Width = 80
<span style="color:Green; TextCol.Resizable = DataGridViewTriState.True
<span style="color:Green; DataGridView1.Columns.Add(TextCol)
<span style="color:Green; DataGridView1.Columns.Item("CurRate").Visible = False
TextCol = <span style="color:Blue; New DataGridViewTextBoxColumn()
TextCol.HeaderText = <span style="color:#A31515; "Credit"
TextCol.DataPropertyName = myDataSet.Tables(<span style="color:#A31515; "Details").Columns(<span style="color:#A31515; "Credit").ToString
<span style="color:Green; TextCol.ReadOnly = True
TextCol.Width = 100
TextCol.Resizable = DataGridViewTriState.<span style="color:Blue; True
DataGridView1.Columns.Add(TextCol)
TextCol = <span style="color:Blue; New DataGridViewTextBoxColumn()
TextCol.HeaderText = <span style="color:#A31515; "Debit"
TextCol.DataPropertyName = myDataSet.Tables(<span style="color:#A31515; "Details").Columns(<span style="color:#A31515; "Debit").ToString
<span style="color:Green; TextCol.ReadOnly = True
TextCol.Width = 100
TextCol.Resizable = DataGridViewTriState.<span style="color:Blue; True
DataGridView1.Columns.Add(TextCol)
DataGridView1.Columns.Remove(<span style="color:#A31515; "DocNo")
cmdDocument = <span style="color:Blue; New OleDbCommand(<span style="color:#A31515; "SELECT Document.* FROM(Document) ORDER BY Document.DocNo", con)
daDocument = <span style="color:Blue; New OleDbDataAdapter(cmdDocument)
cmdBldDocument = <span style="color:Blue; New OleDbCommandBuilder(daDocument)
daDocument.Fill(myDataSet, <span style="color:#A31515; "Document")
CmbCol = <span style="color:Blue; New DataGridViewComboBoxColumn()
CmbCol.HeaderText = <span style="color:#A31515; "Document"
<span style="color:Green; CmbCol.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing
CmbCol.DataPropertyName = <span style="color:#A31515; "DocNo"
CmbCol.DataSource = myDataSet.Tables(<span style="color:#A31515; "Document")
CmbCol.DisplayMember = <span style="color:#A31515; "DocName"
CmbCol.ValueMember = <span style="color:#A31515; "DocNo"
CmbCol.Width = 100
DataGridView1.Columns.Add(CmbCol)
DataGridView1.Columns.Remove(<span style="color:#A31515; "ANoC")
cmdANoCTable = <span style="color:Blue; New OleDbCommand(<span style="color:#A31515; "SELECT ANoCTable.* FROM(ANoCTable) ORDER BY ANoCTable.ANoC", con)
daANoCTable = <span style="color:Blue; New OleDbDataAdapter(cmdANoCTable)
cmdBldANoCTable = <span style="color:Blue; New OleDbCommandBuilder(daANoCTable)
daANoCTable.Fill(myDataSet, <span style="color:#A31515; "ANoCTable")
CmbCol = <span style="color:Blue; New DataGridViewComboBoxColumn()
CmbCol.HeaderText = <span style="color:#A31515; "ANoCTable"
<span style="color:Green; CmbCol.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing
CmbCol.DataPropertyName = <span style="color:#A31515; "ANoC"
CmbCol.DataSource = myDataSet.Tables(<span style="color:#A31515; "ANoCTable")
CmbCol.DisplayMember = <span style="color:#A31515; "ANoNameC"
CmbCol.ValueMember = <span style="color:#A31515; "ANoC"
CmbCol.Width = 100
DataGridView1.Columns.Add(CmbCol)
TextCol = <span style="color:Blue; New DataGridViewTextBoxColumn()
TextCol.HeaderText = <span style="color:#A31515; "Info"
TextCol.DataPropertyName = myDataSet.Tables(<span style="color:#A31515; "Details").Columns(<span style="color:#A31515; "Info").ToString
<span style="color:Green; TextCol.ReadOnly = True
TextCol.Width = 205
TextCol.Resizable = DataGridViewTriState.<span style="color:Blue; True
DataGridView1.Columns.Add(TextCol)
DataGridView1.Columns.Item(<span style="color:#A31515; "Info").Visible = <span style="color:Blue; False
<span style="color:Green; con.Close()
<span style="color:Green; con = Nothing
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub DataGridView1_Enter(<span style="color:Blue; ByVal sender <span style="color:Blue; As <span style="color:Blue; Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles DataGridView1.Enter
<span style="color:Blue; Me.masterBS.EndEdit()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub TDate_Enter(<span style="color:Blue; ByVal sender <span style="color:Blue; As <span style="color:Blue; Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles TDate.Enter
<span style="color:Blue; Me.detailsBS.EndEdit()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub CmdDel_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles CmdDel.Click
<span style="color:Blue; Dim SQLDelete <span style="color:Blue; As <span style="color:Blue; String = <span style="color:#A31515; "DELETE FROM Master WHERE TNo = " & TNo.Text
con = <span style="color:Blue; New OleDbConnection(<span style="color:#A31515; "Provider=Microsoft.jet.oledb.4.0;data source=E:BooksManagerBooksManager.mdb")
con.Open()
cmd = <span style="color:Blue; New OleDbCommand(<span style="color:#A31515; "DELETE FROM Master WHERE TNo = " & TNo.Text, con)
<span style="color:Blue; Try
con.Open()
cmd.ExecuteNonQuery()
<span style="color:Blue; Call LastTNo()
<span style="color:Blue; Catch ex <span style="color:Blue; As OleDb.OleDbException
MsgBox(<span style="color:#A31515; "Error Occurred:" & ex.ToString)
<span style="color:Blue; Finally
con.Close()
<span style="color:Green; If con.State = ConnectionState.Open Then con.Close()
<span style="color:Blue; End <span style="color:Blue; Try
<span style="color:Blue; Call LastTNo()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub CmdRefresh_Click(sender <span style="color:Blue; As System.Object, e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles CmdRefresh.Click
<span style="color:Blue; Call LastTNo()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; End <span style="color:Blue; Class<br/><br/>
[/code]
<hr class="sig Wire & Wireless Network Engineer
View the full article