Ablity to Update DataSet from DataGrid

E

ETuggle

I have a question for anyone that could help.

I've been working on this project for the last couple of months and I'm stuck.
I'm using an access database. Some of the database tables have primary keys,
but this is a query that I have to use.

I filled a Dataset with the query from the access database and then I use a
SELECT statement to fill the Datagrid based on what customer name the user
selects from a Datalist box.

But here's my problem, what I would like to happen is that when someone deletes
or adds a record to the Datagrid that It removes it from the Dataset. What
happens is that when you remove it from the Datagrid it doesn't remove it from
the dataset. I've tried all the update commands, but nothing removes from the
database. The command builder works fine for the tables I have with a primary
key, but for this one that is based on a query it refuses to remove the record.

Does anyone know of a way to manually write the commands so what when I update
the Datagrid, no matter what I do (ex: after I remove or add a record), I can
update the dataset so that I can then update the access database. Because I
need to use a query there is no way that I can add a primary key to this
database. I've already tried to trick it by using the primary key from the
customer database, but that failed.

I'm doing this for work, migrated from VB6 to VB.Net recently, but I'm stuck
here and its not covered in any book I have. What's really a headache is that
every book mentions that I should use a table with a primary key, but what
happens when you "Don't" have one or have to use a query to get your work done?

Thanks for any help in advance.
 
S

Steven Stein [MSFT]

Hello,
To delete the correct record you can call the ExecuteNonQuery method of the
DataCommand.

Check out these topics in the Visual Studio Help:

Executing Updates or Database Commands using a Data Command
http://msdn.microsoft.com/library/en-us/vbcon/html/vbtskexecutingupdatesorda
tabasecommandsusingdatacommand.asp

OleDbCommand.ExecuteNonQuery Method
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemDataOleDbOleDb
CommandClassExecuteNonQueryTopic.asp



Hope that helps,
Steve
VB.Net team
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
 

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

Top