T
Tech Aspirant
Guest
Hello,
In my Case, I have one MDIParent Form "MAIN" and one child form "add_instock".In child form i am updating dataset on click event by editing datagridview. But the problem is dataset is not getting update untill i switch the child form or reloads the parent form.Please Help.
Switching between form is done with the help of menustrip on the MDIParent form.
Public Class MAIN
Private Sub MAIN_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
System.Windows.Forms.Application.Exit() Exit the Application
End Sub
Private Sub INSTOCKToolStripMenuItem1_Click(sender As System.Object, e As System.EventArgs) Handles INSTOCKToolStripMenuItem1.Click
Dim VB_Add_InStock As New Add_InStock()
Set the Parent Form of the Child window.
VB_Add_InStock.MdiParent = Me
Display the new form
VB_Add_InStock.Show()
End Sub
Below is the code of Child Form
Imports Npgsql
Imports System.Data
Imports System.Data.SqlClient
Public Class Add_InStock
Dim adap As NpgsqlDataAdapter
Dim ds As DataSet
Dim cmdbl As NpgsqlCommandBuilder
Dim Command As NpgsqlCommand
Dim data_Table1 As New DataTable
Private Sub Add_InStock_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
TODO: This line of code loads data into the DataSet2.add_instock table. You can move, or remove it, as needed.
Me.Add_instockTableAdapter.Fill(Me.DataSet2.add_instock)
Me.WindowState = FormWindowState.Maximized Maximise the add in stock form
Connection string of the POSTGRE SQL database
Try
Dim connstring As String = String.Format("Server=127.0.0.1;Port=5432;" +
"Username=postgres;Password=Maestro;Database=SRUTILITY;")
Dim conn As NpgsqlConnection = New NpgsqlConnection(connstring)
conn.Open()
Dim Command As NpgsqlCommand = New NpgsqlCommand("SELECT date,nameofmaterial,companymanufacturer,productnumber,serialnumber FROM add_instock ORDER by srnum DESC LIMIT 25", conn)
Dim reader As NpgsqlDataReader = Command.ExecuteReader()
Dim data_Table1 As New DataTable
data_Table1.Load(reader)
DataGridView1.DataSource = data_Table1
reader.Close()
conn.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
code to align the datagridview header as well as the datagridview content
DataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomCenter
DataGridView1.DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomCenter
code to change the datagridview header text
DataGridView1.Columns(0).HeaderText = "Date"
DataGridView1.Columns(1).HeaderText = "Name of Material"
DataGridView1.Columns(2).HeaderText = "Company Manufacturer"
DataGridView1.Columns(3).HeaderText = "Product Number"
DataGridView1.Columns(4).HeaderText = "Serial Number"
Code to programatically add checkbox column in datagridview
Dim dataGridViewCheckBoxColumnObject As DataGridViewCheckBoxColumn = New DataGridViewCheckBoxColumn()
DataGridView1.Columns.Add(dataGridViewCheckBoxColumnObject)
dataGridViewCheckBoxColumnObject.Name = "Cell_Delete"
DataGridView1.Columns(5).HeaderText = "Delete"
dataGridViewCheckBoxColumnObject.TrueValue = "Yes"
End Sub
Update Button
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Me.Validate()
Me.Add_instockTableAdapter.Update(Me.DataSet2.add_instock)
MessageBox.Show("Information Updated Successfully!")
End Sub
Continue reading...
In my Case, I have one MDIParent Form "MAIN" and one child form "add_instock".In child form i am updating dataset on click event by editing datagridview. But the problem is dataset is not getting update untill i switch the child form or reloads the parent form.Please Help.
Switching between form is done with the help of menustrip on the MDIParent form.
Public Class MAIN
Private Sub MAIN_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
System.Windows.Forms.Application.Exit() Exit the Application
End Sub
Private Sub INSTOCKToolStripMenuItem1_Click(sender As System.Object, e As System.EventArgs) Handles INSTOCKToolStripMenuItem1.Click
Dim VB_Add_InStock As New Add_InStock()
Set the Parent Form of the Child window.
VB_Add_InStock.MdiParent = Me
Display the new form
VB_Add_InStock.Show()
End Sub
Below is the code of Child Form
Imports Npgsql
Imports System.Data
Imports System.Data.SqlClient
Public Class Add_InStock
Dim adap As NpgsqlDataAdapter
Dim ds As DataSet
Dim cmdbl As NpgsqlCommandBuilder
Dim Command As NpgsqlCommand
Dim data_Table1 As New DataTable
Private Sub Add_InStock_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
TODO: This line of code loads data into the DataSet2.add_instock table. You can move, or remove it, as needed.
Me.Add_instockTableAdapter.Fill(Me.DataSet2.add_instock)
Me.WindowState = FormWindowState.Maximized Maximise the add in stock form
Connection string of the POSTGRE SQL database
Try
Dim connstring As String = String.Format("Server=127.0.0.1;Port=5432;" +
"Username=postgres;Password=Maestro;Database=SRUTILITY;")
Dim conn As NpgsqlConnection = New NpgsqlConnection(connstring)
conn.Open()
Dim Command As NpgsqlCommand = New NpgsqlCommand("SELECT date,nameofmaterial,companymanufacturer,productnumber,serialnumber FROM add_instock ORDER by srnum DESC LIMIT 25", conn)
Dim reader As NpgsqlDataReader = Command.ExecuteReader()
Dim data_Table1 As New DataTable
data_Table1.Load(reader)
DataGridView1.DataSource = data_Table1
reader.Close()
conn.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
code to align the datagridview header as well as the datagridview content
DataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomCenter
DataGridView1.DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomCenter
code to change the datagridview header text
DataGridView1.Columns(0).HeaderText = "Date"
DataGridView1.Columns(1).HeaderText = "Name of Material"
DataGridView1.Columns(2).HeaderText = "Company Manufacturer"
DataGridView1.Columns(3).HeaderText = "Product Number"
DataGridView1.Columns(4).HeaderText = "Serial Number"
Code to programatically add checkbox column in datagridview
Dim dataGridViewCheckBoxColumnObject As DataGridViewCheckBoxColumn = New DataGridViewCheckBoxColumn()
DataGridView1.Columns.Add(dataGridViewCheckBoxColumnObject)
dataGridViewCheckBoxColumnObject.Name = "Cell_Delete"
DataGridView1.Columns(5).HeaderText = "Delete"
dataGridViewCheckBoxColumnObject.TrueValue = "Yes"
End Sub
Update Button
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Me.Validate()
Me.Add_instockTableAdapter.Update(Me.DataSet2.add_instock)
MessageBox.Show("Information Updated Successfully!")
End Sub
Continue reading...