A Strange Issue with DataGrid

S

Sajid

Hello,

I am trying to bind a DataTable to a Grid which will allow users to
Edit data and then submit the changes back to the Database. I want to
display values in the Grid satisfying a particular criteria like
follows:

Dim tbl as new DataTable
For Each row As DataRow In DataTableName.Rows
If (row.Item("ColumnName") Is System.DBNull.Value) Then
tbl.Rows.Add(row.ItemArray)
End If
Next

Grid.DataSource = tbl

But on the other hand I have created and Filled the DataTableName
dataTable as follows:

DataAdapter.Fill(DataTableName)

After the user has done changes on the Grid (e.g. Deleted few rows,
modifies few column values or added few rows), I want to Update the
Table and I issue the following command for that:

DataAdapter.Update(tbl)

Which gives me a problem that the Rows are not properly updated rather
multiple records are added for nothing and many other problems are
seen in the original table.

Also I cannot Update using the following:

DataAdapter.Update(DataTableName)

because I didn't bind the DataTableName DataTable to the Grid because
I only want to display records in the Grid satisfying certain
criteria.

Has anyone any idea how to make it work or modify my logic.

cheers
 
C

Cor

Hi Sajid,

Your have in my opinion defintily have to look first to the dataview (very
easy to handle in combination with a datagrid) and the SQL or OleDb
commandbuilder.

Know also that deleting rows from the datagrid using the "del" key on the
keyboard will delete the row but also the information that it is deleted and
therefore never update the database.

Do also not forget to do before the update the currencymanager
endcurrentedit methode

I hope this helps for a start?

Cor
 

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