Parry Chana

Parry Chana

  • NA
  • 1
  • 0

Datagrid ADO.Net dataset update record

May 4 2009 1:23 PM
hello vb genius,

i'm good in programming but not too familiar with ado.net. I'm trying to make a simple application using mssql server, ado.net, .net 3.5 and sp's

I have following question

1. created a table with 2 fields (id , name) id is pk
2. created sp to add, delete, update/insert record in table.
3. created a form and shown two text fields to show the data from table and a grid to show all the record on the same form. 2 buttons added on the form new and save
4. create sqlconnection to server, create data adapter and set the data adapter insert, select and update command alongwith parameters and filled the data source.
5. bound the grid runtime with datasource and table.
6. on cellclick of datagrid, i get the record from grid and show the value in text fields. even grid is sorted, it is working find, i found some function from internet to achieve it.
7. on click of new button, i clear the text fields and internally set a boolean variable for new record.
8. on click of save button, if boolean varaible is true then add new row to dataset table and accept the changes.
9. it adds the record in table and show it in grid.


till this point everything worked fine.

the issue i'm facing is when user select a record from grid and do the changes on text field, on click of save, it need to update the record.

as i have boolean variable which tell me if it is exisiting or new record but i'm unable to find out the way to update the record.

there is a way i can do it, if i know the current record number in table of data set. in this case i can set the value of table coloumsn of that row and accept changes

but i have no way to get the row of the table becuase if grid is sorted then i don't have correct correspoding record number in data table.

how i can achieve this functionality? In a nutshell, if i able to get corresponding record number of table in dataset on basis of current selected grid record, it will solve the above problem.

at the same time i'm open for any or most practical approach.

any idea?

thanks in advance,

p