473,396 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

DataGrid will not Update and Save changes

I have a datagrid on a form that update properly when form loads. When the program runs and I type in/add a new row in the datagrid, it does not save the changes. Any help would be greatly appreaciated. Thanks.

Code below:

Imports System.Data.OleDb
Public Class Form2
Inherits System.Windows.Forms.Form


#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents butExit As System.Windows.Forms.Button
Friend WithEvents butSave As System.Windows.Forms.Button
Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.butExit = New System.Windows.Forms.Button
Me.DataGrid1 = New System.Windows.Forms.DataGrid
Me.butSave = New System.Windows.Forms.Button
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginIni t()
Me.SuspendLayout()
'
'butExit
'
Me.butExit.Location = New System.Drawing.Point(600, 312)
Me.butExit.Name = "butExit"
Me.butExit.Size = New System.Drawing.Size(160, 24)
Me.butExit.TabIndex = 8
Me.butExit.Text = "Exit"
'
'DataGrid1
'
Me.DataGrid1.CaptionText = "Employee Information"
Me.DataGrid1.DataMember = ""
Me.DataGrid1.Dock = System.Windows.Forms.DockStyle.Top
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(0, 0)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.Size = New System.Drawing.Size(784, 232)
Me.DataGrid1.TabIndex = 9
'
'butSave
'
Me.butSave.Location = New System.Drawing.Point(600, 272)
Me.butSave.Name = "butSave"
Me.butSave.Size = New System.Drawing.Size(160, 24)
Me.butSave.TabIndex = 10
Me.butSave.Text = "Save Changes"
'
'Form2
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(784, 374)
Me.Controls.Add(Me.butSave)
Me.Controls.Add(Me.DataGrid1)
Me.Controls.Add(Me.butExit)
Me.Name = "Form2"
Me.Text = "Form2"
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit( )
Me.ResumeLayout(False)

End Sub

#End Region

Private m_DataAdapter As OleDbDataAdapter
Private m_DataSet As New DataSet


Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
m_DataAdapter = New OleDbDataAdapter( _
"SELECT * FROM Emp", _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\PR\Payroll.mdb")

' Map the default name Table to Books.
m_DataAdapter.TableMappings.Add("Table", "Emp")

' Fill the DataSet.
m_DataAdapter.Fill(m_DataSet)

' Bind the DataGrid to the DataSet's first DataTable.
DataGrid1.DataSource = m_DataSet.Tables(0)

' Give the columns sane widths.
Dim table_style As New DataGridTableStyle
table_style.MappingName = "Emp"
DataGrid1.TableStyles.Add(table_style)
table_style.GridColumnStyles(0).Width = 200
table_style.GridColumnStyles(1).Width = 200
End Sub

Private Sub butExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butExit.Click
Me.Close()
End Sub

Private Sub Form2_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
' Make a command builder to generate INSERT,
' UPDATE, and DELETE commands as necessary.

Dim command_builder As New OleDbCommandBuilder(m_DataAdapter)


' Save any changes.
m_DataAdapter.Update(m_DataSet)
End Sub
End Class
Aug 27 '06 #1
0 3608

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Randy | last post by:
Hello All, I'm trying to discover the best way to handle the situation where you have a datagrid in your app and someone changes a cell but doesn't leave that cell (so there's the little pencil...
4
by: Glenn Owens | last post by:
I have a DataGrid web control which I've dynamically populated with template columns to be used for bulk-editting. Generally, all of the columns are textbox and/or dropdownlist child controls. ...
3
by: Kevin Pedersen | last post by:
Hello, I am using an editable datagrid. After I save the changes the datagrid shows the old values. I've read the posts about the Page_Load and not binding the datagrid each time. The SQL that...
7
by: Joe | last post by:
Hi, I’m new to asp.net. I want to create an asp.net page that allows user to edit the data. I have pasted my code below. I am able to display the data in a datagrid. At the bottom of the page...
2
by: dbuchanan | last post by:
Where is the logic error that causes the attached code to adds two rows instead on one to the datagrid? The code correctly update the datasource with one row, but the datagrid gets two new rows....
3
by: Jim | last post by:
I have a datagrid with a DataAdapter as the DataSource. The user fills in their data for 3 columns and I want to programically add a value to the 4th (invisible) column (employee number). That way...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
0
by: gtyler | last post by:
When you make changes to a DataGrid a picture of a Pencil appears on the right hand side. As I understand it, the DataSource is not updated until you move off that row and the Pencil disappears. ...
11
by: gyap88 | last post by:
Hello i m using vb 2005 express to do my project. I m suppose to create a datagrid to allow user to make changes to the database. The program display the database in a datagrid where users can juz...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.