Can't update field in datagrid

  • Thread starter Chumley the Walrus
  • Start date
C

Chumley the Walrus

Even tho all my field names are named right, I cannot figure why I am
getting a
"Specified argument was out of the range of valid values. Parameter
name: index" error on the line that holds " Dim sport As textbox =
E.Item.cells(2).Controls(0)". Below is the entire subroutine to
update/edit data on the datagrid in use:

Sub MyDataGrid_UpdateCommand(s As Object, e As
DataGridCommandEventArgs )
Dim conn As SqlConnection
Dim MyCommand As SqlCommand
Dim strConn as string =
"SERVER=207.42.67.18;UID=sa;PWD=mystery;DATABASE=dbHandicapperArticles;"
Dim sport As textbox = E.Item.cells(2).Controls(0)
Dim articleheader As textbox = E.Item.cells(3).Controls(0)
Dim articletext As textbox = E.Item.cells(4).Controls(0)
Dim fpick As textbox = E.Item.cells(5).Controls(0)
Dim strUpdateStmt As String
strUpdateStmt =" UPDATE tblArticles SET" & _
" sport =@sport, articleheader =@articleheader, fpick =@fpick,
articletext = @articletext " & _
" WHERE articleID = @articleID"
conn = New SqlConnection(strConn)
MyCommand = New SqlCommand(strUpdateStmt, conn)
MyCommand.Parameters.Add(New SQLParameter("@sport", sport.text))
MyCommand.Parameters.Add(New SQLParameter("@articleheader",
articleheader.text))
MyCommand.Parameters.Add(New SQLParameter("@articletext",
articletext.text))
MyCommand.Parameters.Add(New SQLParameter("@fpick", fpick.text))
MyCommand.Parameters.Add(New SQLParameter("@articleID",
e.Item.Cells(1).Text ))
conn.Open()
MyCommand.ExecuteNonQuery()
MyDataGrid.EditItemIndex = -1
conn.close
BindData
End Sub


thanks in advance
chum
 
C

Cor Ligthert

Hi Chumley,

Is this OleDb add than the parameters in the sequence of your SQL string
(they are now not)?

I think that that will help?

Cor

Even tho all my field names are named right, I cannot figure why I am
 
C

Chumley the Walrus

Cor Ligthert said:
Hi Chumley,

Is this OleDb add than the parameters in the sequence of your SQL string
(they are now not)?

I think that that will help?

No, I'm using the system.data.sqlclient classes:

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQLClient" %>
 
C

Cor Ligthert

Hi Chumley,

I saw parameter and was focused on the Parameters.

Is there a special reason that you do not use something simple as?

Dim sporttext As string = E.Item.cells(2).text
MyCommand.Parameters.Add(New SQLParameter("@sport", sporttext))


Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top