Advertisement

05.13.2008 at 01:00PM PDT, ID: 23399240
[x]
Attachment Details

Need help fixing a simple class

Asked by MrManderson in Microsoft Visual Basic.Net, MS SQL Server, Visual Studio 2008

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.ConnectionString)
        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(dataTable)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

End Class

Many Thanks
Steve
Start Free Trial
[+][-]05.13.2008 at 01:17PM PDT, ID: 21558882

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]05.13.2008 at 01:26PM PDT, ID: 21558965

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.13.2008 at 01:34PM PDT, ID: 21559033

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.13.2008 at 02:00PM PDT, ID: 21559244

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual Basic.Net, MS SQL Server, Visual Studio 2008
Sign Up Now!
Solution Provided By: dstanley9
Participating Experts: 3
Solution Grade: A
 
 
[+][-]05.13.2008 at 02:41PM PDT, ID: 21559545

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.13.2008 at 03:13PM PDT, ID: 21559763

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.13.2008 at 03:40PM PDT, ID: 21559906

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]05.13.2008 at 04:37PM PDT, ID: 21560187

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628