|
-
Oct 27th, 2003, 06:06 AM
#1
Thread Starter
Member
Update SQL Server Table Using DataGrid Connected To DataSet
Hi,
I am using data grid connected to a DataSet object in VB.NET.
When I fill the fields manually in the DataGrid the Data is Updated (using the DataAdapter Mapping) and everything works great. BUT- When I am filling the DataGrid from code (Data Integrity of Default values) the data grid update only the previews record so each update batch it does not update the last modified record.
For Example:
-----------------
If I getting empty recordset and therefor the DataGrid is empty and I write 2 new records, the two records will be insert to the Table mapping BUT the Fields that I had been changed from code (Data Integrity) will saved for the first record only.
Here is the code I am Using:
---------------------------------------------------------------------------------
First I Build the DataSet Object and Connect it to The Datagrid...
...
...
---------------------------------------------------------------------------------
'Automatically Fields Update
Dim row As Int64
Dim col As Int64
For row = 0 To rpt.ds.Tables("CashTbl").Rows.Count - 1
For col = 0 To rpt.ds.Tables("CashTbl").Columns.Count - 1
'Put "." where it findes Null
If col = 1 Or col = 2 Or col = 4 Or col = 5 Or col = 6 Then
If Not IsNumeric(DataGrid1.Item(row, col)) Then
DataGrid1.Item(row, col) = "."
End If
End If
Next
Next
DataGrid1.Update()
--------------------------------------------------------------------------------
If ds.HasChanges = True Then
Dim cmd As SqlClient.SqlCommandBuilder
Dim DataAdapter As SqlClient.SqlDataAdapter
DataAdapter = New SqlClient.SqlDataAdapter(SelectStr, cn)
DataAdapter.TableMappings.Add("Table", "CashTbl")
cmd = New SqlClient.SqlCommandBuilder(DataAdapter)
cmd.GetUpdateCommand.CommandText)
DataAdapter.Update(ds, "CashTbl")
End If
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|