?
Solved

Sql Update

Posted on 2011-10-14
9
Medium Priority
?
226 Views
Last Modified: 2013-11-26
Hi Experts
I use the following code to change some fields

       CS.Open()
        DA.Fill(DS, "Codes")
    count = grid3.Rows.Count
            For X = 1 To 30 - count
                Dim newCustomersRow As DataRow = DS.Tables("Codes").NewRow()
                newCustomersRow("Prefix") = "M"
                newCustomersRow("a3") = GroupBox.Text
                newCustomersRow("a10") = "@" + GroupBox.Text + "@@"
                newCustomersRow("KeyCode") = KeycodeMax.Text + X
                newCustomersRow("SubKey1") = "0"
                DS.Tables("Codes").Rows.Add(newCustomersRow)
            Next
          dt = DS.Tables("codes")
            dt.DefaultView.RowFilter = "a3 ='" & GroupBox.Text & "'"
            grid1.DataSource = dt
When I use foloowing code to update
     
     CS.Open()
            cmdBuilder = New SqlCommandBuilder(DA)
            DA.Update(DS, "Codes")
            MsgBox("Changes Saved")

It updates all the rows from Grid1 except the first row, where the pointer is.
If I move the pointer in the grid1 to second row then Update,     it updates all the rows.
I would like to update all the rows without moving the pointer in the grid1.
Please help
0
Comment
Question by:b001
  • 5
  • 4
9 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36967163
You are only inserting rows right? Do you mean it does not insert the first added row?
0
 

Author Comment

by:b001
ID: 36967335
HI CodeCruiser:
I only insert rows if the count is less than 30.
The first row is always exist.
It does not update if the pointer is on the first row in the grid.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36967993
>I only insert rows if the count is less than 30.

>It does not update

Do you change some values as well? Programmatically?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:b001
ID: 36968098
Yes . I do make changes to all rows Programmtically.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36968427
Hmm. You can change the selectedindex of the grid programmatically as well. Try with that and see if it updates the changes.
0
 

Author Comment

by:b001
ID: 36969001
Hi CodeCruiser:
Please write the code for me.
Thnaks
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36969092
Grid1.SelectedIndex = 1
0
 

Author Comment

by:b001
ID: 36969147
I have the following error

'SelectedIndex'  is not a not a member of 'System.Windows.Forms.DataGridView'
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 36969203
Grid1.CurrentCell = Grid1.Item(0, 1)
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question