Click here to Skip to main content
15,904,024 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sir ,
I have the problem to update the database, when i make changes and then in get the exception selectcommand that does not return any base table information
My code is
VB
Imports System.Data.SqlClient

Public Class Form1

    Dim connetionString As String

    Dim connection As SqlConnection

    Dim adapter As SqlDataAdapter

    Dim cmdBuilder As SqlCommandBuilder

    Dim ds As New DataSet

    Dim changes As DataSet

    Dim sql As String

    Dim i As Int32



    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password"

        connection = New SqlConnection(connetionString)

        Sql = "select * from Product"

        Try

            connection.Open()

            adapter = New SqlDataAdapter(Sql, connection)

            adapter.Fill(ds)

            connection.Close()

            DataGridView1.Data Source= ds.Tables(0)

        Catch ex As Exception

            MsgBox(ex.ToString)

        End Try

    End Sub



    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Try

            cmdBuilder = New SqlCommandBuilder(adapter)

            changes = ds.GetChanges()

            If changes IsNot Nothing Then

                adapter.Update(changes)

            End If

            MsgBox("Changes Done")

        Catch ex As Exception

            MsgBox(ex.ToString)

        End Try

    End Sub

End Class

Please help me


[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 21-Jul-12 0:52am
v2
Comments
Christian Graus 21-Jul-12 6:06am    
This is a code dump. Where do you get your error ? I assume this is for a class, it has a lot of problems that stop it being production level code.
Abdul Quader Mamun 21-Jul-12 6:55am    
I think you should place connection close command in finally block.
[no name] 21-Jul-12 10:55am    
You are probably getting this specific error because you have only defined a SELECT statement. Nowhere have you defined an UPDATE statement.

1 solution

You need to define commands and then execute command builder.

Start from here: MSDN: Generating Commands with CommandBuilders (ADO.NET)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900