T
Tech Aspirant
Guest
Hello,
In My Project there are two child forms (child form 1:- Add_InStock,Child form 2:- View_InStock) and one MDI Parent form (MAIN).In Child Form 1 i am inserting data into the
Database using the Button Control (Add Button) and displaying TOP 25 data into the datagridview.In Child form 2 i amd displaying the complete data till date in the datagridviw.
I want to Edit the datagridview and update the database present in child form 1 using the button control(Update Button). But the problem is when i am editing the datagridview and
click on the update button it shows the message of confirmation that the datagriview is updated and then when i navigate to child form 2 in order to see the change ; there
i cant see any change i am not able to see the updated datagridview.
The starnge behaviour is that when i again navigate and edit datagridview present in child form 1 it gets updated successfully and shows the edited data in datagridview
present in child form 1.
Conclusion is that at the second time it is updating after navigating to the other child form rather updating at the first time.
Imports System.Windows.Forms
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 MAIN_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Code to Align the Form Title Text at the Centre
Dim g As Graphics = Me.CreateGraphics()
Dim startingPoint As Double = (Me.Width / 2) - (g.MeasureString(Me.Text.Trim, Me.Font).Width / 2)
Dim widthOfASpace As Double = g.MeasureString(" ", Me.Font).Width
Dim tmp As String = " "
Dim tmpWidth As Double = 0
Do
tmp += " "
tmpWidth += widthOfASpace
Loop While (tmpWidth + widthOfASpace) < startingPoint
Me.Text = tmp & tmp & Me.Text.Trim & tmp & tmp
Me.WindowState = FormWindowState.Maximized MaximizeBox The MAIN Form
Code to Change the background color of the MDI Parent (MAIN) Form
Dim child As Control
For Each child In Me.Controls
If TypeOf child Is MdiClient Then
child.BackColor = Color.White
Exit For
End If
Next
child = Nothing
Dim VB_TITLE As New TITLE()
Set the Parent Form of the Child window.
VB_TITLE.MdiParent = Me
Display the new form
VB_TITLE.Show()
ToolStripStatusLabel1.Text = Format(Now, "dd/MM/yyyy")
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()
Add_InStock.Show()
Me.Hide()
End Sub
Private Sub EXITToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles EXITToolStripMenuItem.Click
System.Windows.Forms.Application.Exit() Exit the Application
End Sub
Private Sub INSTOCKToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles INSTOCKToolStripMenuItem.Click
Dim VB_VIEW_InStock As New VIEW_InStock()
Set the Parent Form of the Child window.
VB_VIEW_InStock.MdiParent = Me
Display the new form
VB_VIEW_InStock.Show()
End Sub
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
Dim ID As Integer
Private Sub Add_InStock_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
VIEW_InStock.Close()
TODO: This line of code loads data into the DataSet2.add_instock table. You can move, or remove it, as needed.
Add_instockTableAdapter.Fill(Me.DataSet2.add_instock)
Me.WindowState = FormWindowState.Maximized Maximise the add in stock form
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"
End Sub
Add Button
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
DateTimePicker1.Value = DateTimePicker1.Value.ToShortDateString
Try
Dim connstring As String = String.Format("Server=127.0.0.1;Port=5432;" +
"Username=xxxx;Password=xxxx;Database=SRUTILITY;")
Dim conn As NpgsqlConnection = New NpgsqlConnection(connstring)
conn.Open()
Dim Command As NpgsqlCommand = New NpgsqlCommand("INSERT INTO add_instock values(" + DateTimePicker1.Value + "," + TextBox1.Text + "," + TextBox2.Text + "," + TextBox3.Text + "," + TextBox4.Text + ")", conn)
Command.ExecuteNonQuery()
conn.Close()
MessageBox.Show("Data Saved.Click OK to Continue")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
After inserting clears all the textboxes
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
Try
Dim connstring As String = String.Format("Server=127.0.0.1;Port=5432;" +
"Username=xxxx;Password=xxxx;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
Try
Dim connstring As String = String.Format("Server=127.0.0.1;Port=5432;" +
"Username=xxxx;Password=xxxx;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
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
mports Npgsql
Imports Microsoft.Office.Interop
Public Class VIEW_InStock
Dim connstring As String = String.Format("Server=127.0.0.1;Port=5432;" +
"Username=xxx;Password=xxxx;Database=SRUTILITY;")
Dim conn As NpgsqlConnection = New NpgsqlConnection(connstring)
Private Sub VIEW_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)
Add_InStock.Close()
Me.WindowState = FormWindowState.Maximized
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"
End Sub
Continue reading...
In My Project there are two child forms (child form 1:- Add_InStock,Child form 2:- View_InStock) and one MDI Parent form (MAIN).In Child Form 1 i am inserting data into the
Database using the Button Control (Add Button) and displaying TOP 25 data into the datagridview.In Child form 2 i amd displaying the complete data till date in the datagridviw.
I want to Edit the datagridview and update the database present in child form 1 using the button control(Update Button). But the problem is when i am editing the datagridview and
click on the update button it shows the message of confirmation that the datagriview is updated and then when i navigate to child form 2 in order to see the change ; there
i cant see any change i am not able to see the updated datagridview.
The starnge behaviour is that when i again navigate and edit datagridview present in child form 1 it gets updated successfully and shows the edited data in datagridview
present in child form 1.
Conclusion is that at the second time it is updating after navigating to the other child form rather updating at the first time.
Imports System.Windows.Forms
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 MAIN_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Code to Align the Form Title Text at the Centre
Dim g As Graphics = Me.CreateGraphics()
Dim startingPoint As Double = (Me.Width / 2) - (g.MeasureString(Me.Text.Trim, Me.Font).Width / 2)
Dim widthOfASpace As Double = g.MeasureString(" ", Me.Font).Width
Dim tmp As String = " "
Dim tmpWidth As Double = 0
Do
tmp += " "
tmpWidth += widthOfASpace
Loop While (tmpWidth + widthOfASpace) < startingPoint
Me.Text = tmp & tmp & Me.Text.Trim & tmp & tmp
Me.WindowState = FormWindowState.Maximized MaximizeBox The MAIN Form
Code to Change the background color of the MDI Parent (MAIN) Form
Dim child As Control
For Each child In Me.Controls
If TypeOf child Is MdiClient Then
child.BackColor = Color.White
Exit For
End If
Next
child = Nothing
Dim VB_TITLE As New TITLE()
Set the Parent Form of the Child window.
VB_TITLE.MdiParent = Me
Display the new form
VB_TITLE.Show()
ToolStripStatusLabel1.Text = Format(Now, "dd/MM/yyyy")
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()
Add_InStock.Show()
Me.Hide()
End Sub
Private Sub EXITToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles EXITToolStripMenuItem.Click
System.Windows.Forms.Application.Exit() Exit the Application
End Sub
Private Sub INSTOCKToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles INSTOCKToolStripMenuItem.Click
Dim VB_VIEW_InStock As New VIEW_InStock()
Set the Parent Form of the Child window.
VB_VIEW_InStock.MdiParent = Me
Display the new form
VB_VIEW_InStock.Show()
End Sub
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
Dim ID As Integer
Private Sub Add_InStock_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
VIEW_InStock.Close()
TODO: This line of code loads data into the DataSet2.add_instock table. You can move, or remove it, as needed.
Add_instockTableAdapter.Fill(Me.DataSet2.add_instock)
Me.WindowState = FormWindowState.Maximized Maximise the add in stock form
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"
End Sub
Add Button
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
DateTimePicker1.Value = DateTimePicker1.Value.ToShortDateString
Try
Dim connstring As String = String.Format("Server=127.0.0.1;Port=5432;" +
"Username=xxxx;Password=xxxx;Database=SRUTILITY;")
Dim conn As NpgsqlConnection = New NpgsqlConnection(connstring)
conn.Open()
Dim Command As NpgsqlCommand = New NpgsqlCommand("INSERT INTO add_instock values(" + DateTimePicker1.Value + "," + TextBox1.Text + "," + TextBox2.Text + "," + TextBox3.Text + "," + TextBox4.Text + ")", conn)
Command.ExecuteNonQuery()
conn.Close()
MessageBox.Show("Data Saved.Click OK to Continue")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
After inserting clears all the textboxes
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
Try
Dim connstring As String = String.Format("Server=127.0.0.1;Port=5432;" +
"Username=xxxx;Password=xxxx;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
Try
Dim connstring As String = String.Format("Server=127.0.0.1;Port=5432;" +
"Username=xxxx;Password=xxxx;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
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
mports Npgsql
Imports Microsoft.Office.Interop
Public Class VIEW_InStock
Dim connstring As String = String.Format("Server=127.0.0.1;Port=5432;" +
"Username=xxx;Password=xxxx;Database=SRUTILITY;")
Dim conn As NpgsqlConnection = New NpgsqlConnection(connstring)
Private Sub VIEW_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)
Add_InStock.Close()
Me.WindowState = FormWindowState.Maximized
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"
End Sub
Continue reading...