none
Can you check my code please? Is it the good way of working? RRS feed

  • Question

  • Dim Connection As New OleDb.OleDbConnection(My.Settings.ConnectionString)
    
    Dim sql As String = "SELECT * From tblOverallKPI where Datum = '" & Format(mDate, "MM/dd/yyyy") & "'"
    
    Dim Adapter As New OleDb.OleDbDataAdapter(sql, Connection)
    
    Dim Builder As New OleDb.OleDbCommandBuilder(Adapter)
    
    Dim ds As New DataSet()
    
    Dim row As DataRow
    
    Dim tblOverallKPI As DataTable
    
    Dim insertMode As Boolean
    
    
    
    Adapter.Fill(ds, "tblOverallKPI")
    
    tblOverallKPI = ds.Tables("tblOverallKPI")
    
    insertMode = (tblOverallKPI.Rows.Count = 0)
    
    
    
    If insertMode Then
    
       row = tblOverallKPI.NewRow
    
       row("Datum") = mDate
    
    Else   
    ' we are in edit mode
    row = tblOverallKPI.Rows(0)
    End If row("CptrNotifications") = objErrors.NotificationsCptr row("CptrWarningsLevel1") = objErrors.WarningsYellowCptr row("CptrWarningsLevel2") = objErrors.WarningsRedCptr If insertMode Then
    ' here we add the new line tblOverallKPI.Rows.Add(row) Else
    ' here we send the updated data Adapter.UpdateCommand = Builder.GetUpdateCommand End If Adapter.Update(ds, "tblOverallKPI")
    Monday, May 25, 2009 4:38 PM

Answers

  • Nothing particularly wrong that I can see except you should parameterize your queries using the parameter classes. After you update, you should call the AcceptChanges to your DataTable(s).
    John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
    Monday, May 25, 2009 8:31 PM

All replies

  • Nothing particularly wrong that I can see except you should parameterize your queries using the parameter classes. After you update, you should call the AcceptChanges to your DataTable(s).
    John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
    Monday, May 25, 2009 8:31 PM

  • > After you update, you should call the AcceptChanges to your DataTable(s).

    BTW, the default AcceptChangesDuringUpdate will do this for you.
    Monday, May 25, 2009 10:53 PM
  • Thanks BinaryCoder
    John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
    Monday, May 25, 2009 11:53 PM
  • Hi Theirrly

    After writting Adapter.Update(ds, "tblOverallKPI") ,you have to call AcceptChanges()

    eg:ds.AcceptChanges()


    PS.Shakeer Hussain Hyderabad
    Tuesday, May 26, 2009 4:38 AM