Results 1 to 2 of 2

Thread: DataAdapter Update problem

  1. #1

    Thread Starter
    Member
    Join Date
    May 2003
    Posts
    53

    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

  2. #2
    Lively Member
    Join Date
    May 2003
    Posts
    78
    Hi,

    THis is how I change a field's value in a record in a table:



    VB Code:
    1. dim objDataSet as new DataSet
    2. objConnection = new Connection
    3.  
    4. 'Modify column of row
    5.  
    6. objDataSet.Tables([COLOR=deeppink]TABLENAME[/COLOR]).Rows([COLOR=deeppink]ROWNUMBER[/COLOR]).Item([COLOR=deeppink]COLUMNNAMEINROWTOUPDATE[/COLOR]) = [COLOR=deeppink]VALUETOUPDATEROWWITH [/COLOR]
    7.  
    8. 'And then the dataadapter bit:
    9.  
    10.                 objConnection.Open()
    11.  
    12.         objDataAdapt.UpdateCommand = New OleDbCommand()
    13.         objDataAdapt.UpdateCommand.Connection = objConnection
    14.  
    15.         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]  & "]"
    16.  
    17.         objDataAdapt.UpdateCommand.CommandType = CommandType.Text
    18.         objDataAdapt.UpdateCommand.ExecuteNonQuery()
    19.         objDataAdapt.Update(objDataSet, [COLOR=deeppink]TABLENAME[/COLOR] )
    20.         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
  •  



Click Here to Expand Forum to Full Width