Trouble Updating Dataset from DataGrid

  • Thread starter Thread starter Gary Paris
  • Start date Start date
G

Gary Paris

I have a bound datagrid on my windowsform. I have the following
declarations in the global module of the project:

Public eDS As DataSet
Public eDA As OleDb.OleDbDataAdapter


In the Load routine of the form, I have the following code

Dim eDS As New DataSet
Dim eDA As New OleDbDataAdapter
Dim e_strSQL As String

e_strSQL = "SELECT sysid, newDate, newTime , [desc] FROM event
WHERE con_id = '" & _
g_ContactID & "' ORDER BY newDate DESC"

eDA = New OleDbDataAdapter(e_strSQL, CN)
eDA.Fill(eDS, "Event")
Dim cb As New OleDbCommandBuilder(eDA)

DataGrid1.DataSource = eDS
DataGrid1.DataMember = eDS.Tables(0).TableName



This code works, and the table is filled.
When I try to update, using the following code, I get an error, "Object
reference not set to an instance of an object"

eDA.Update(eDS, "Event")



What am I missing?



Thanks,



Gary
 
Gary:

Have you set the UpdateCommand property of your DataAdapter so it knows how
to update the datasource?

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


I have a bound datagrid on my windowsform. I have the following
declarations in the global module of the project:

Public eDS As DataSet
Public eDA As OleDb.OleDbDataAdapter


In the Load routine of the form, I have the following code

Dim eDS As New DataSet
Dim eDA As New OleDbDataAdapter
Dim e_strSQL As String

e_strSQL = "SELECT sysid, newDate, newTime , [desc] FROM event
WHERE con_id = '" & _
g_ContactID & "' ORDER BY newDate DESC"

eDA = New OleDbDataAdapter(e_strSQL, CN)
eDA.Fill(eDS, "Event")
Dim cb As New OleDbCommandBuilder(eDA)

DataGrid1.DataSource = eDS
DataGrid1.DataMember = eDS.Tables(0).TableName



This code works, and the table is filled.
When I try to update, using the following code, I get an error, "Object
reference not set to an instance of an object"

eDA.Update(eDS, "Event")



What am I missing?



Thanks,



Gary
 
Not sure how to set it or where to put it. Can you provide more details
please?

Thanks,

Gary
 
I thought the OleDbCommandBuilder creates the update code automatically? I
remember having a problem a few months ago and I was told to insert this
command. It worked and my data was updated. I took the roughly the same
code and tried again in a new project, but it isn't working. Maybe I'm
missing something.

HELP
 
Gary,

You have set the creation of a new referenced dataset in the load routine.

It still exist at update time, so you can get the dataset from the datagrid.

However you need that dataadapter with its builded commands as well, and
therefore I would keep it on.
Dim eDS As New DataSet
Dim eDA As New OleDbDataAdapter
eDS = BNew Dataset
eDa = New OleDbAdapter.

However in the way you do it has it not much sense you can do as well
Public eDS As DataSet
Public eDA As OleDb.OleDbDataAdapter
Public eDS as New Dataset
Public eDa as new OleDb.OleDbDataAdapter

I hope this helps,

Cor
 
Cor,

I made the changes you suggested and now I get an "Syntax error in UPDATE
statement"

I thought the update code was generated by the OLEDBCommandBuilder statement
that I put in the code. Did it not do it correctly?

Thanks,

Gary
 
Gary,

Can you try to use the table names in your program in the same case as it is
in the Select statement, sometimes is that the trouble. As well is it often
the trouble that there is a reserved SQL word is used.

I hope this give some help

Cor
 
Cor,

Finally figured out what it is. I did look at the names and they are the
same. So I then looked at the field names in the select statement. One
field was [desc], so i renamed it desc1 and removed the brackets. Problem
solved.

Thanks for your suggestion.

Gary
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top