Imports System.Data.SqlClient
Imports System.Data.OleDb
Public Class fNew
Private da As New SqlDataAdapter
Private bsource As BindingSource = New BindingSource()
Dim sql As String = "SELECT * FROM tblNew_IDL "
Dim dt As DataTable = ds.Tables("New")
Dim sect As String
Dim dept As String
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
sect = cmbSect.Text
dept = cmbDept.Text
sqlconn.Open()
If sect = Nothing Then
MessageBox.Show("Please input Section")
sqlconn.Close()
Exit Sub
End If
If dept = Nothing Then
MessageBox.Show("Please input Department")
sqlconn.Close()
Exit Sub
End If
da = New SqlDataAdapter(sql, sqlconn)
ds = New DataSet()
da.Fill(ds, "New")
bsource.DataSource = ds.Tables("New")
'To filter base on selected section and department
bsource.Filter = "section='" & sect & "' And department='" & dept & "'"
Me.DataGridView1.DataSource = bsource
Me.DataGridView1.Columns(0).Visible = False
Me.DataGridView1.Columns(1).Visible = False
Me.DataGridView1.Columns(2).Visible = False
sqlconn.Close()
End Sub
Private Sub fNew_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
sqlconn.ConnectionString = connString
da = New SqlDataAdapter(sql, sqlconn)
ds = New DataSet()
'Dim commandBuilder As SqlCommandBuilder = New SqlCommandBuilder(da)
da.Fill(ds, "New")
bsource.DataSource = ds.Tables("New")
Me.DataGridView1.DataSource = bsource
'Me.DataGridView1.Columns(0).Visible = False
'Me.DataGridView1.Columns(1).Visible = False
'Me.DataGridView1.Columns(2).Visible = False
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
' Update the database with the user's changes.
sqlconn.Open()
Try
Me.DataGridView1.BindingContext(dt).EndCurrentEdit()
Me.da.Update(dt)
Catch ex As SqlException
MsgBox("Error updating the table" + ex.Message)
sqlconn.Close()
Exit Sub
End Try
MessageBox.Show("Table is updated sucessful!")
End Sub
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
sect = cmbSect.Text
dept = cmbDept.Text
sqlconn.Open()
If sect = Nothing Then
MessageBox.Show("Please input Section")
sqlconn.Close()
Exit Sub
End If
If dept = Nothing Then
MessageBox.Show("Please input Department")
sqlconn.Close()
Exit Sub
End If
da = New SqlDataAdapter(sql, sqlconn)
ds = New DataSet()
da.Fill(ds, "New")
bsource.DataSource = ds.Tables("New")
'To filter base on selected section and department
bsource.Filter = "section='" & sect & "' And department='" & dept & "'"
Me.DataGridView1.DataSource = bsource
Me.DataGridView1.Columns(0).Visible = False
Me.DataGridView1.Columns(1).Visible = False
Me.DataGridView1.Columns(2).Visible = False
End Sub
End Class