473,400 Members | 2,163 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,400 software developers and data experts.

Can't Update Datagridview

I just can't seem to get the datagridview to update. I'm using 2005 vb.net

Here's my code for loading the grid (works fine) and my attempt at updating
via a save button...

Private SxAdapter As New OleDbDataAdapter()
Private SxSource As New BindingSource()
Private SxTable As New DataTable()

Private Sub GetData(ByVal selectCommand As String)
Try
SQL = "Select LastName, FirstName, TestName, TestDate, Score
from TestScores"
SxAdapter = New OleDbDataAdapter(selectCommand, CS)
Dim MyCommandBuilder As New OleDbCommandBuilder(SxAdapter)
SxTable.Locale = System.Globalization.CultureInfo.InvariantCulture
Me.SxAdapter.Fill(SxTable)
Me.SxSource.DataSource = SxTable
Catch ex As OleDbException
MessageBox.Show("Error")
End Try
End Sub

in the form load...
Me.DataGridView1.DataSource = Nothing
Me.DataGridView1.Rows.Clear()
Me.DataGridView1.DataSource = SxSource
GetData("Select LastName, FirstName, TestName, TestDate, Score from
TestScores")

and the save button...

Try
Me.Validate()
Me.SxSource.EndEdit()
Dim myBuilder As OleDb.OleDbCommandBuilder = New
OleDb.OleDbCommandBuilder(Me.SxAdapter)
Me.SxAdapter.Update(CType(Me.SxSource.DataSource, DataTable))
MsgBox("Update Successful")
Catch ex As Exception
MsgBox("Update Failed")
End Try

I'm stumpled...
Nov 28 '06 #1
4 5255
What does it do? Does it give you an error? Does it just act like
it did the update but it doesn't? In what way doesn't it work?

Robin S.
-------------------------------------------
"Arne Beruldsen" <Ar***********@discussions.microsoft.comwrote in message
news:13**********************************@microsof t.com...
>I just can't seem to get the datagridview to update. I'm using 2005 vb.net

Here's my code for loading the grid (works fine) and my attempt at
updating
via a save button...

Private SxAdapter As New OleDbDataAdapter()
Private SxSource As New BindingSource()
Private SxTable As New DataTable()

Private Sub GetData(ByVal selectCommand As String)
Try
SQL = "Select LastName, FirstName, TestName, TestDate, Score
from TestScores"
SxAdapter = New OleDbDataAdapter(selectCommand, CS)
Dim MyCommandBuilder As New OleDbCommandBuilder(SxAdapter)
SxTable.Locale =
System.Globalization.CultureInfo.InvariantCulture
Me.SxAdapter.Fill(SxTable)
Me.SxSource.DataSource = SxTable
Catch ex As OleDbException
MessageBox.Show("Error")
End Try
End Sub

in the form load...
Me.DataGridView1.DataSource = Nothing
Me.DataGridView1.Rows.Clear()
Me.DataGridView1.DataSource = SxSource
GetData("Select LastName, FirstName, TestName, TestDate, Score from
TestScores")

and the save button...

Try
Me.Validate()
Me.SxSource.EndEdit()
Dim myBuilder As OleDb.OleDbCommandBuilder = New
OleDb.OleDbCommandBuilder(Me.SxAdapter)
Me.SxAdapter.Update(CType(Me.SxSource.DataSource, DataTable))
MsgBox("Update Successful")
Catch ex As Exception
MsgBox("Update Failed")
End Try

I'm stumpled...

Nov 28 '06 #2
Robin...

via the Catch...I simply get "Update Failed"

I'm confused...

"RobinS" wrote:
What does it do? Does it give you an error? Does it just act like
it did the update but it doesn't? In what way doesn't it work?

Robin S.
-------------------------------------------
"Arne Beruldsen" <Ar***********@discussions.microsoft.comwrote in message
news:13**********************************@microsof t.com...
I just can't seem to get the datagridview to update. I'm using 2005 vb.net

Here's my code for loading the grid (works fine) and my attempt at
updating
via a save button...

Private SxAdapter As New OleDbDataAdapter()
Private SxSource As New BindingSource()
Private SxTable As New DataTable()

Private Sub GetData(ByVal selectCommand As String)
Try
SQL = "Select LastName, FirstName, TestName, TestDate, Score
from TestScores"
SxAdapter = New OleDbDataAdapter(selectCommand, CS)
Dim MyCommandBuilder As New OleDbCommandBuilder(SxAdapter)
SxTable.Locale =
System.Globalization.CultureInfo.InvariantCulture
Me.SxAdapter.Fill(SxTable)
Me.SxSource.DataSource = SxTable
Catch ex As OleDbException
MessageBox.Show("Error")
End Try
End Sub

in the form load...
Me.DataGridView1.DataSource = Nothing
Me.DataGridView1.Rows.Clear()
Me.DataGridView1.DataSource = SxSource
GetData("Select LastName, FirstName, TestName, TestDate, Score from
TestScores")

and the save button...

Try
Me.Validate()
Me.SxSource.EndEdit()
Dim myBuilder As OleDb.OleDbCommandBuilder = New
OleDb.OleDbCommandBuilder(Me.SxAdapter)
Me.SxAdapter.Update(CType(Me.SxSource.DataSource, DataTable))
MsgBox("Update Successful")
Catch ex As Exception
MsgBox("Update Failed")
End Try

I'm stumpled...


Nov 28 '06 #3
Robin...

The error reads

Dynamic SQL generation for the UpdateCommand is not supported against a
SelectCommand that does not return any key column information.

??

Arne

"RobinS" wrote:
What does it do? Does it give you an error? Does it just act like
it did the update but it doesn't? In what way doesn't it work?

Robin S.
-------------------------------------------
"Arne Beruldsen" <Ar***********@discussions.microsoft.comwrote in message
news:13**********************************@microsof t.com...
I just can't seem to get the datagridview to update. I'm using 2005 vb.net

Here's my code for loading the grid (works fine) and my attempt at
updating
via a save button...

Private SxAdapter As New OleDbDataAdapter()
Private SxSource As New BindingSource()
Private SxTable As New DataTable()

Private Sub GetData(ByVal selectCommand As String)
Try
SQL = "Select LastName, FirstName, TestName, TestDate, Score
from TestScores"
SxAdapter = New OleDbDataAdapter(selectCommand, CS)
Dim MyCommandBuilder As New OleDbCommandBuilder(SxAdapter)
SxTable.Locale =
System.Globalization.CultureInfo.InvariantCulture
Me.SxAdapter.Fill(SxTable)
Me.SxSource.DataSource = SxTable
Catch ex As OleDbException
MessageBox.Show("Error")
End Try
End Sub

in the form load...
Me.DataGridView1.DataSource = Nothing
Me.DataGridView1.Rows.Clear()
Me.DataGridView1.DataSource = SxSource
GetData("Select LastName, FirstName, TestName, TestDate, Score from
TestScores")

and the save button...

Try
Me.Validate()
Me.SxSource.EndEdit()
Dim myBuilder As OleDb.OleDbCommandBuilder = New
OleDb.OleDbCommandBuilder(Me.SxAdapter)
Me.SxAdapter.Update(CType(Me.SxSource.DataSource, DataTable))
MsgBox("Update Successful")
Catch ex As Exception
MsgBox("Update Failed")
End Try

I'm stumpled...


Nov 28 '06 #4
Do you have a primary key defined in your table? And does your SELECT
statement include that field?

Robin S.
===========================
"Arne Beruldsen" <Ar***********@discussions.microsoft.comwrote in message
news:0E**********************************@microsof t.com...
Robin...

The error reads

Dynamic SQL generation for the UpdateCommand is not supported against a
SelectCommand that does not return any key column information.

??

Arne

"RobinS" wrote:
>What does it do? Does it give you an error? Does it just act like
it did the update but it doesn't? In what way doesn't it work?

Robin S.
-------------------------------------------
"Arne Beruldsen" <Ar***********@discussions.microsoft.comwrote in
message
news:13**********************************@microso ft.com...
>I just can't seem to get the datagridview to update. I'm using 2005
vb.net

Here's my code for loading the grid (works fine) and my attempt at
updating
via a save button...

Private SxAdapter As New OleDbDataAdapter()
Private SxSource As New BindingSource()
Private SxTable As New DataTable()

Private Sub GetData(ByVal selectCommand As String)
Try
SQL = "Select LastName, FirstName, TestName, TestDate, Score
from TestScores"
SxAdapter = New OleDbDataAdapter(selectCommand, CS)
Dim MyCommandBuilder As New OleDbCommandBuilder(SxAdapter)
SxTable.Locale =
System.Globalization.CultureInfo.InvariantCulture
Me.SxAdapter.Fill(SxTable)
Me.SxSource.DataSource = SxTable
Catch ex As OleDbException
MessageBox.Show("Error")
End Try
End Sub

in the form load...
Me.DataGridView1.DataSource = Nothing
Me.DataGridView1.Rows.Clear()
Me.DataGridView1.DataSource = SxSource
GetData("Select LastName, FirstName, TestName, TestDate, Score from
TestScores")

and the save button...

Try
Me.Validate()
Me.SxSource.EndEdit()
Dim myBuilder As OleDb.OleDbCommandBuilder = New
OleDb.OleDbCommandBuilder(Me.SxAdapter)
Me.SxAdapter.Update(CType(Me.SxSource.DataSource,
DataTable))
MsgBox("Update Successful")
Catch ex As Exception
MsgBox("Update Failed")
End Try

I'm stumpled...



Nov 28 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: thomasp | last post by:
I know this is a vague question, but I am not sure what information to give. I am using VB2005 beta and the datagridview is pulling data from one of three tables in an Access database. For some...
1
by: Dave | last post by:
I have a table with 3 fields of which the primary key is a autonumber. I have created my dataadapter, dataset and datagridview using a wizard. However, in the datagrid, the update and delete...
6
by: Greg P | last post by:
I am using VS2005 and have been learning a ton about databinding. I know that when you drag a view from the datasource window (creating a dataGridView) that an update method is not added to the...
14
by: joey.powell | last post by:
I am using VS2005 for a windows forms application. I need to be able to use a worker thread function to offload some processing from the UI thread. The worker thread will need access to a...
2
by: Ivan | last post by:
I have a class Foo which have two property. I have a thread that do some process and update class Foo int B. I have a datagridview on main form. this datagridview data source to this class Foo and...
3
by: =?Utf-8?B?THVib21pcg==?= | last post by:
Hi, I have a DataGridView that displays data from one table from database. I didn’t implement any my code, I just used wizard to do all the work with DatagridView populating. Visual Studio...
1
by: sklett | last post by:
I've got a strange situation here. I have a databound DataGridView that also has un-bound columns. When the view loads, I want to update the values of the unbound columns. If I attempt to modify...
6
by: insirawali | last post by:
Hi all, I have this problem, i need to know is there a way i cn use the data adapter's update method in this scenario. i have 3 tables as below create table table1{ id1 int identity(1,1)...
2
by: Oleg Subachev | last post by:
I have DataGridView which DataSource is assigned to Table<> object of DataContext connected to SQL Server database. But when the underlying SQL Server database is updated (through ODBC...
0
by: bharathi228 | last post by:
Hi, iam working with windows application.here my requirement is binding data to database from a datagridview. next i want to update some rows in datagridview and update it to the database.for...
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: 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?
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.