We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,590 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

How to update SQL CE database using datagridview

Dear All,

I have a small probelm with updating my database. Here are my codes

Module AphidSimVar
    Dim myCon As SqlCeConnection = New SqlCeConnection("Data Source=|DataDirectory|\AphidModel.sdf")
    Dim myCmd As SqlCeCommand
    Dim myAdap As SqlCeDataAdapter
    Dim myDataSet As DataSet
    Dim myTable As DataTable
    Dim myBuilder As SqlCeCommandBuilder

    Public Sub ShowData()
        myCmd = New SqlCeCommand("Select * FROM AphidPop", myCon)
        If myCon.State = ConnectionState.Closed Then myCon.Open()
        myAdap = New SqlCeDataAdapter(myCmd)
        myDataSet = New DataSet()
        myAdap.Fill(myDataSet, "AphidData")
        frmPredatorPop.DataGridView1.DataSource = myDataSet.Tables("AphidData").DefaultView
        myTable = myDataSet.Tables("AphidData")
        myCon.Close()
        myCon = Nothing
    End Sub
    Public Sub myUpdate()
        myBuilder = New SqlCeCommandBuilder(myAdap)
        myAdap.Update(myTable)
    End Sub
End Module

I use VB.NET 2010 and SQL Server Compact 3.5 database. I want to load existing data in the database and change/add and then update. My "View Data" button will call "ShowData" and its working. Then I can add new data but cannot change existing data using above "myUpdate" procedure. Please help me. I am new to VB.NET and database. Error message is "Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information."
Thanks

1
Contributor
0
Replies
1
View
zhouy
Newbie Poster
15 posts since Mar 2012
Reputation Points: 15
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0541 seconds using 2.68MB