I have an admin script to modify data in an Access db, but when I hit the
update button after changing a field, I get a "Specified argument was out of
the range of valid values. Parameter name: index" error at the line where
I'm declaring my 'phone' variable. This subroutine worked with another table
I was working with , but I'm wondering why the numerical assignment is
having problems.
Thanks in advance
Bill
''
Sub MyDataGrid_Upda teCommand(s As Object, e As DataGridCommand EventArgs )
Dim conn As OleDbConnection
Dim MyCommand As OleDbCommand
Dim strConn as string = "Provider=Micro soft.Jet.OLEDB. 4.0;Data
Source=E:\web\m ydomain\db\mydb .mdb;"
Dim company As textbox = E.Item.cells(2) .Controls(0)
Dim address As textbox = E.Item.cells(3) .Controls(0)
Dim city As textbox = E.Item.Cells(4) .Controls(0)
Dim state As textbox = E.Item.cells(5) .Controls(0)
Dim county As textbox = E.Item.cells(6) .Controls(0)
Dim zip As textbox = E.Item.cells(7) .Controls(0)
Dim phone As textbox = E.Item.cells(8) .Controls(0)
Dim descript As textbox = E.Item.cells(9) .Controls(1)
Dim web As textbox = E.Item.cells(10 ).Controls(0)
Dim email As textbox = E.Item.cells(11 ).Controls(0)
Dim datesold As textbox = E.Item.cells(12 ).Controls(0)
Dim dateexpire As textbox = E.Item.cells(13 ).Controls(0)
Dim strUpdateStmt As String
strUpdateStmt =" UPDATE CPAs SET" & _
" company = @company, address = @address, city = @city, state = @state, " &
_
"county = @county, zip = @zip, phone = @phone, descript =@ descript, " & _
"web = @web, email = @email, datesold = @datesold, dateexpire = @dateexpire"
& _
" WHERE cpaID = @cpaID"
conn = New OleDbConnection (strConn)
MyCommand = New OleDbCommand(st rUpdateStmt, conn)
MyCommand.Param eters.Add(New OleDbParameter( "@company", company.text))
MyCommand.Param eters.Add(New OleDbParameter( "@address", address.text))
MyCommand.Param eters.Add(New OleDbParameter( "@city", city.text))
MyCommand.Param eters.Add(New OleDbParameter( "@state", state.text))
MyCommand.Param eters.Add(New OleDbParameter( "@county", county.text))
MyCommand.Param eters.Add(New OleDbParameter( "@zip", zip.text))
MyCommand.Param eters.Add(New OleDbParameter( "@phone", phone.text))
MyCommand.Param eters.Add(New OleDbParameter( "@descript" , descript.text))
MyCommand.Param eters.Add(New OleDbParameter( "@web", web.text))
MyCommand.Param eters.Add(New OleDbParameter( "@email", email.text))
MyCommand.Param eters.Add(New OleDbParameter( "@datesold" , datesold.text))
'', dateexpire =@dateexpire
MyCommand.Param eters.Add(New OleDbParameter( "@dateexpir e", dateexpire.text ))
MyCommand.Param eters.Add(New OleDbParameter( "@cpaID",
e.Item.Cells(1) .Text ))
conn.Open()
MyCommand.Execu teNonQuery()
MyDataGrid.Edit ItemIndex = -1
conn.close
BindData
End Sub
''