Link to home
Start Free TrialLog in
Avatar of b001
b001Flag for Afghanistan

asked on

Sql Update

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
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

You are only inserting rows right? Do you mean it does not insert the first added row?
Avatar of b001

ASKER

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.
>I only insert rows if the count is less than 30.

>It does not update

Do you change some values as well? Programmatically?
Avatar of b001

ASKER

Yes . I do make changes to all rows Programmtically.
Hmm. You can change the selectedindex of the grid programmatically as well. Try with that and see if it updates the changes.
Avatar of b001

ASKER

Hi CodeCruiser:
Please write the code for me.
Thnaks
Grid1.SelectedIndex = 1
Avatar of b001

ASKER

I have the following error

'SelectedIndex'  is not a not a member of 'System.Windows.Forms.DataGridView'
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial