Hi Fellow EE'rs
I am trying to make a class that will fill an SQL data adapter from an SQL database. I am also trying to get it to update the database with any changes etc..
I can get the class to fill the grid with data however cannot get it to update back to the db, as Im new to vb.net im not so hot when it comes to db interaction due to being used to recordsets.
I would appreciate it if someone could take a look at the following class and help me fix it so it will actually update my table. Also any recommendations on changes to the way im trying to implement the class would be great too :0)
I am currently getting "The DataAdapter.SelectCommand property needs to be initialized" error
Imports System.Data.SqlClient
Imports DevExpress.XtraGrid.Views.
Base
Imports DevExpress.XtraGrid
Imports System.Data.Common
Public Class SQLClass
Private adapter As New SqlDataAdapter()
Private SourceDataSet As New DataSet()
Public Function GetData(ByVal SQLStr As String) As DataTable
Dim Connection As New SqlConnection(My.Settings.
Connection
String)
Dim adapter As New SqlDataAdapter()
Dim SelectCommand = New SqlCommand(SQLStr, Connection)
adapter.SelectCommand = SelectCommand
adapter.Fill(SourceDataSet
)
Return SourceDataSet.Tables(0)
End Function
Public Sub UpdateDatasource(ByVal grid As GridControl)
Dim cb As New SqlCommandBuilder(adapter)
Dim View As ColumnView = grid.FocusedView
If Not (View.PostEditor() And View.UpdateCurrentRow()) Then Return
DoUpdateTable(adapter, SourceDataSet.Tables(0))
End Sub
Public Sub DoUpdateTable(ByVal dataAdapter As SqlDataAdapter, ByVal dataTable As DataTable)
Try
dataAdapter.Update(dataTab
le)
Catch ex As Exception
MessageBox.Show(ex.Message
)
End Try
End Sub
End Class
Many Thanks
Steve
Start Free Trial