Advertisement

[x]
Attachment Details

Updating DataGridView From SQL Server Using Visual Basic 2005

[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.3
Hello,

I am new to VB, and trying to figure out the best way display database (MS SQL server 2005)  information in a program (probably inside datagridview's).  I found this code snippet, which seems to work well enough.  But when I attempt to use it to 'save' information to the data it generates the error 'Update requires a valid UpdateCommand when passed DataRow collection with modified rows.'.  From my reading it seems that the table adapter doesn't have enough info to generate the update command from the select statement.  The select is 'SELECT * FROM dbo.people'.  I have already ensured that Visual Studio knows about the table and its relationships by adding all of that information (regarding primary keys, FK's, etc) into the appropriate areas (I even completed the diagrams).  

Is there a way to update some part of this so that it can automatically generate and then execute the update commands?  

Thanks all,

Rob
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
Public Class Form1
    Dim connectionString As String = "server=192.168.1.15;uid=sa;pwd=;database=emp_review_data"
    Dim myDataSet As DataSet
    Dim myDataAdapter As SqlDataAdapter
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim commandString As String = "Select name, empNum from reviewData" ' empNum is unique identifier
        myDataAdapter = New SqlDataAdapter(commandString, connectionString)
        myDataSet = New DataSet()
        myDataAdapter.Fill(myDataSet, "reviewData")
        Me.DataGridView1.DataSource = myDataSet.Tables("reviewData")
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        myDataAdapter.Update(myDataSet, "reviewData")
    End Sub
End Class
Related Solutions
Related Solutions
 
Loading Advertisement...
 

Rank: Genius

Accepted Solution by jpaulino:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
Loading Advertisement...
20080924-EE-VQP-40 / EE_QW_Related_20080208