468,784 Members | 1,471 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,784 developers. It's quick & easy.

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 5097
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by thomasp | last post: by
6 posts views Thread by Greg P | last post: by
14 posts views Thread by joey.powell | last post: by
3 posts views Thread by =?Utf-8?B?THVib21pcg==?= | last post: by
6 posts views Thread by insirawali | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
2 posts views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.