|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Can't Update DatagridviewHere'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... 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. ------------------------------------------- Show quoteHide quote "Arne Beruldsen" <ArneBeruld***@discussions.microsoft.com> wrote in message news:13E650C9-F9A6-4DEE-8BDD-E647EC23540A@microsoft.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... Robin...
via the Catch...I simply get "Update Failed" I'm confused... Show quoteHide quote "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" <ArneBeruld***@discussions.microsoft.com> wrote in message > news:13E650C9-F9A6-4DEE-8BDD-E647EC23540A@microsoft.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... > > > 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 Show quoteHide quote "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" <ArneBeruld***@discussions.microsoft.com> wrote in message > news:13E650C9-F9A6-4DEE-8BDD-E647EC23540A@microsoft.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... > > > Do you have a primary key defined in your table? And does your SELECT
statement include that field? Robin S. =========================== Show quoteHide quote "Arne Beruldsen" <ArneBeruld***@discussions.microsoft.com> wrote in message news:0E2850AE-EADA-4BA3-9C60-9A09668E7990@microsoft.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" <ArneBeruld***@discussions.microsoft.com> wrote in >> message >> news:13E650C9-F9A6-4DEE-8BDD-E647EC23540A@microsoft.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... >> >> >>
word automation vb.net
Arranging window screens on multi-monitor Desktop Re: Help needed in using FSO's, TextStreams, etc. --- Code Review and Advice requested better way to program than this? set refresh rate for an active browser window newbie syntax question: adding event handler for button not working How broad should an interface be? Advice needed. File and Database Search Re: Is VB.NET Stable?? Error on deleting registry value |
|||||||||||||||||||||||