|
-
Jun 29th, 2003, 05:43 AM
#1
Thread Starter
Member
DataAdapter Update problem
dim Dr as datarow
Dim Dt As DataTable = dg1.datasoursse
Dim Hit As DataGrid.HitTestInfo
Hit = DG1.HitTest(e.X, e.Y)
Dr = Dt.Rows(Hit.Row)
Dr.BeginEdit()
Dr("fieldname") = "xyx"
Dim Ds_temp As DataSet = Ds1.GetChanges(DataRowState.Modified) ' Ds1 is the main Dataset attached to the Datagrid DG1
Adp1.Update(Ds_temp)
Dr.AcceptChanges()
In the above code , I am modifing a field but , the dataset says that neither of the field is changed or modified , hence I get the problem in the next line when updating DATAADAPTER Adp1.
Where am I wrong
Syed Nadeemulla Hussaini
# I-2,C & FM Quater
Hutti Gold Mines Co Ltd.
Raichur Karnataka
INDIA
-
Jun 29th, 2003, 07:12 AM
#2
Lively Member
Hi,
THis is how I change a field's value in a record in a table:
VB Code:
dim objDataSet as new DataSet
objConnection = new Connection
'Modify column of row
objDataSet.Tables([COLOR=deeppink]TABLENAME[/COLOR]).Rows([COLOR=deeppink]ROWNUMBER[/COLOR]).Item([COLOR=deeppink]COLUMNNAMEINROWTOUPDATE[/COLOR]) = [COLOR=deeppink]VALUETOUPDATEROWWITH [/COLOR]
'And then the dataadapter bit:
objConnection.Open()
objDataAdapt.UpdateCommand = New OleDbCommand()
objDataAdapt.UpdateCommand.Connection = objConnection
objDataAdapt.UpdateCommand.CommandText = "UPDATE [" & [COLOR=deeppink]TABLENAME[/COLOR] & "] SET [" & [COLOR=deeppink]TABLENAME[/COLOR] & "]." & [COLOR=deeppink]COLUMNNAMEINROWTOUPDATE[/COLOR] & " = [" & [COLOR=deeppink]TABLENAME[/COLOR] & "]![" & [COLOR=deeppink]COLUMNNAMEINROWTOUPDATE[/COLOR] & "]"
objDataAdapt.UpdateCommand.CommandType = CommandType.Text
objDataAdapt.UpdateCommand.ExecuteNonQuery()
objDataAdapt.Update(objDataSet, [COLOR=deeppink]TABLENAME[/COLOR] )
objConnection.Close()
Something like that although the SQL statement might be slightly wrong.
Hope that helps
CJN
Last edited by CJN; Jun 29th, 2003 at 07:16 AM.
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
|