Saving Data Problem

DekaFlash

Well-known member
Joined
Feb 14, 2006
Messages
117
Programming Experience
1-3
The line in red bold is generating the following error - Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.

Can you please assist? Thanks

VB.NET:
    Private Sub SaveData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveData.Click
        Dim connstring As String = "Data Source=BM-PC;Initial Catalog=EquinexMasterSql;Integrated Security = True"
        Dim sql As String = "select * from TempRatingsData"

        Dim conn As SqlConnection = New SqlConnection(connstring)

        If (Form1.showndata = 1 And Form1.datedata = 0 And Form1.racedata = 0) Then

            conn.Open()

            builder.GetUpdateCommand()
            da.Update(ds, "TempRatingsData")
            da = New SqlDataAdapter(sql, conn)
            da.SelectCommand = New SqlCommand(sql, conn)
            builder = New SqlCommandBuilder(da)

            da.Update(Me.EquinexMasterSqlDataSet, "TempRatingsData")
            Me.EquinexMasterSqlDataSet.Clear()
            da.Fill(Me.EquinexMasterSqlDataSet, "TempRatingsData")
            DataGridView1.DataSource = Me.EquinexMasterSqlDataSet.Tables("TempRatingsData")
            'Me.RatingsDataTableAdapter.Update(Me.EquinexMasterSqlDataSet.RatingsData)
            Me.TempRatingsDataTableAdapter.Update(Me.EquinexMasterSqlDataSet.TempRatingsData)
            conn.Close()
        ElseIf (Form1.showndata = 0 And Form1.datedata = 1 And Form1.racedata = 0) Then
            conn.Open()

[COLOR="Red"]            [B]builder.GetUpdateCommand()[/B]            [/COLOR]da.Update(ds, "TempRatingsData")
            da = New SqlDataAdapter(sql, conn)
            da.SelectCommand = New SqlCommand(sql, conn)
            builder = New SqlCommandBuilder(da)

            da.Update(Me.EquinexMasterSqlDataSet, "TempRatingsData")
            Me.EquinexMasterSqlDataSet.Clear()
            da.Fill(Me.EquinexMasterSqlDataSet, "TempRatingsData")
            DataGridView1.DataSource = Me.EquinexMasterSqlDataSet.Tables("TempRatingsData")
            'Me.RatingsDataTableAdapter.Update(Me.EquinexMasterSqlDataSet.RatingsData)
            Me.TempRatingsDataTableAdapter.Update(Me.EquinexMasterSqlDataSet.TempRatingsData)
            conn.Close()

        ElseIf (Form1.showndata = 0 And Form1.datedata = 0 And Form1.racedata = 1) Then
            conn.Open()

            builder.GetUpdateCommand()

            da = New SqlDataAdapter(sql, conn)
            da.SelectCommand = New SqlCommand(sql, conn)
            builder = New SqlCommandBuilder(da)

            da.Update(Me.EquinexMasterSqlDataSet, "TempRatingsData")
            Me.EquinexMasterSqlDataSet.Clear()
            da.Fill(Me.EquinexMasterSqlDataSet, "TempRatingsData")
            DataGridView1.DataSource = Me.EquinexMasterSqlDataSet.Tables("TempRatingsData")
            'Me.RatingsDataTableAdapter.Update(Me.EquinexMasterSqlDataSet.RatingsData)
            Me.TempRatingsDataTableAdapter.Update(Me.EquinexMasterSqlDataSet.TempRatingsData)
            conn.Close()

        End If
    End Sub
 
Youre on .NET 2. You should be doing your data access in the methods described in the DW2 link in my signature.

Your table does not have a primary key or your select command does not include the key column(s) in its selection list.
 
You seem to have an interesting hybrid of DA methods there, why on earth are you using Dataadapters and tableadapters?

When dealing with Datasets in net 2.0, Tableadapters are the way to go.
 

Latest posts

Back
Top