Advertisement

05.13.2008 at 11:45PM PDT, ID: 23400443
[x]
Attachment Details

Error using ado.net update

Asked by Netlink2 in Visual Studio 2008, Programming for ASP.NET, Visual Studio .NET 2005

I get the error "dynamic sql generation is not supported against a selectcommand that does not return any base table information" when trying to update a table from a datagridview. The error occurs on the line "adapter.Update(dtNotices)".

                Dim cb As SqlCommandBuilder
                cb = New SqlCommandBuilder(adapter)
                Try
                    ' Now let's write the changes back to the database
                    adapter.Update(dtNotices)
                Catch ex As Exception
                    MsgBox("Yikes, Can't update the database" & vbCr & ex.Message, _
                    MsgBoxStyle.Critical, "Error!")
                    Exit Sub
                End TryStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
The code for loading the datagridview is:
    Public Sub ExecuteSP(ByVal DataTableName As String, ByVal strSQL As String)
        'Running stored procedures has been timed as being faster than running SQL commands
        'If DataTableName is nothing, then execute a SQL command, no table returned
        'The DataTables are defined globally in modSQL.vb
        'If a thread and a normal call to this function occur at the same time then a connection error will occur
        'doevents until available
        Do Until SQLprocessing = False
            System.Windows.Forms.Application.DoEvents()
        Loop
        SQLprocessing = True
        dt = New DataTable
        Dim command As SqlCommand = New SqlCommand("usp_ExecString", oConnSQL)
        command.Parameters.Add("@sqlStr", strSQL)
        command.CommandType = CommandType.StoredProcedure
        'Dim adapter As SqlDataAdapter = New SqlDataAdapter(command)
        adapter = New SqlDataAdapter(command)
        Try
            Select Case DataTableName
                Case "dtClient"
                    indexC = 0
                    dtClient = New DataTable
                    adapter.Fill(dtClient)
                Case "dtClientSchedule"
                    dtClientSchedule = New DataTable
                    adapter.Fill(dtClientSchedule)
                Case "dtClientPayment"
                    dtClientPayment = New DataTable
                    adapter.Fill(dtClientPayment)
                Case "dtTemp"
                    dtTemp = New DataTable
                    adapter.Fill(dtTemp)
                Case "dtAddress"
                    dtAddress = New DataTable
                    adapter.Fill(dtAddress)
                Case "dtLandLord"
                    dtLandLord = New DataTable
                    adapter.Fill(dtLandLord)
                Case "dtSecurities"
                    dtSecurities = New DataTable
                    adapter.Fill(dtSecurities)
                Case "dtContacts"
                    dtContacts = New DataTable
                    adapter.Fill(dtContacts)
                Case "dtEmployer"
                    dtEmployer = New DataTable
                    adapter.Fill(dtEmployer)
                Case "dtSQL"
                    dtSQL = New DataTable
                    adapter.Fill(dtSQL)
                Case "dtLocalPayments"
                    dtLocalPayments = New DataTable
                    adapter.Fill(dtLocalPayments)
                Case "dtNotices"
                    dtNotices = New DataTable
                    adapter.Fill(dtNotices)
                Case "dtMessages"
                    dtMessages = New DataTable
                    adapter.Fill(dtMessages)
                Case "dtHistory"
                    dtHistory = New DataTable
                    adapter.Fill(dtHistory)
                Case Else
                    Dim command1 As New SqlCommand(strSQL, oConnSQL)
                    Debug.Print(strSQL)
                    Try
                        Dim cmd As New SqlCommand
                        'Dim p1 As New SqlParameter("@UserName", SqlDbType.NVarChar)
                        'Dim p2 As New SqlParameter("@UserPwd", SqlDbType.NVarChar)
                        'p1.Value = strUser
                        'p2.Value = strPwd
                        'cmd.Parameters.Add(p1)
                        'cmd.Parameters.Add(p2)
                        cmd.Connection = oConnSQL 'cnn
                        If oConnSQL.State = ConnectionState.Closed Then
                            oConnSQL.Open()
                        End If
                        cmd.CommandText = strSQL
                        cmd.ExecuteNonQuery()
 
                    Catch ex As SqlException
                        MsgBox(ex.Message)
                    Catch ex As Exception
                        MsgBox(ex.Message)
                    End Try
                    'Debug.Print(strSQL)
            End Select
        Catch ex As Exception
            Debug.Print(ex.ToString)
            Debug.Print(strSQL)
        End Try
        SQLprocessing = False
[+][-]05.13.2008 at 11:52PM PDT, ID: 21561735

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 11:52PM PDT, ID: 21561736

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.14.2008 at 05:43AM PDT, ID: 21563451

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.14.2008 at 06:12AM PDT, ID: 21563742

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.14.2008 at 06:29AM PDT, ID: 21563902

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.14.2008 at 02:15PM PDT, ID: 21568799

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.14.2008 at 04:20PM PDT, ID: 21569494

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.14.2008 at 05:06PM PDT, ID: 21569698

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.14.2008 at 10:52PM PDT, ID: 21570910

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.15.2008 at 04:50AM PDT, ID: 21572466

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: Visual Studio 2008, Programming for ASP.NET, Visual Studio .NET 2005
Sign Up Now!
Solution Provided By: graye
Participating Experts: 3
Solution Grade: A
 
 
[+][-]05.15.2008 at 04:52AM PDT, ID: 21572480

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.15.2008 at 04:52PM PDT, ID: 21578864

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