R
Russ Green
I am currently learning asp.net (vb) with Web Matrix. I am building an
intranet page that will have an editable datagrid on it. I have got the
datagrid to populate OK but I cannot get the Update method to work
correctly.
I click on edit and and the non-readonly field become editable as in
http://www.russgreen.net/software/newsgroupimages/screenshot1.gif
The update button does nothing. See
http://www.russgreen.net/software/newsgroupimages/screenshot2.gif
Error page
http://www.russgreen.net/software/newsgroupimages/SyntaxerrorinUPDATEstateme
nt_.htm
..aspx page
http://www.russgreen.net/software/newsgroupimages/db_project_list_new.aspx
Can someone please help explain this please?
Sub DataGrid_Update(s As Object, e As DataGridCommandEventArgs )
'create edit text boxes
Dim txtName As textbox = E.Item.cells(2).Controls(0)
Dim txtStatus As textbox = E.Item.cells(3).Controls(0)
Dim txtAction As textbox = E.Item.cells(4).Controls(0)
Dim txtStaff As textbox = E.Item.cells(5).Controls(0)
'update SQL
Dim strUpdateSql As String ="UPDATE Projects SET" & _
" Name =@Name, Status =@Status, Action = @Action, Staff = @Staff" &
_
" WHERE ProjectID = @ProjectID"
'connection stuff
Dim conn As OleDbConnection = New OleDbConnection(strConn)
conn.Open()
'command Object to Execute the SQL
Dim cmd As OleDbCommand = New OleDbCommand(strUpdateSql, conn)
cmd.Parameters.Add(New OleDbParameter("@name", txtName.text))
cmd.Parameters.Add(New OleDbParameter("@Status", txtStatus.text))
cmd.Parameters.Add(New OleDbParameter("@Action", txtAction.text))
cmd.Parameters.Add(New OleDbParameter("@Staff", txtStaff.text))
cmd.Parameters.Add(New OleDbParameter("@ProjectID",
CType(e.Item.Cells(0).Text, Long)))
cmd.ExecuteNonQuery()
'do housekeeping
DataGrid1.EditItemIndex = -1
conn.close
'rebind
BindData()
End Sub
intranet page that will have an editable datagrid on it. I have got the
datagrid to populate OK but I cannot get the Update method to work
correctly.
I click on edit and and the non-readonly field become editable as in
http://www.russgreen.net/software/newsgroupimages/screenshot1.gif
The update button does nothing. See
http://www.russgreen.net/software/newsgroupimages/screenshot2.gif
Error page
http://www.russgreen.net/software/newsgroupimages/SyntaxerrorinUPDATEstateme
nt_.htm
..aspx page
http://www.russgreen.net/software/newsgroupimages/db_project_list_new.aspx
Can someone please help explain this please?
Sub DataGrid_Update(s As Object, e As DataGridCommandEventArgs )
'create edit text boxes
Dim txtName As textbox = E.Item.cells(2).Controls(0)
Dim txtStatus As textbox = E.Item.cells(3).Controls(0)
Dim txtAction As textbox = E.Item.cells(4).Controls(0)
Dim txtStaff As textbox = E.Item.cells(5).Controls(0)
'update SQL
Dim strUpdateSql As String ="UPDATE Projects SET" & _
" Name =@Name, Status =@Status, Action = @Action, Staff = @Staff" &
_
" WHERE ProjectID = @ProjectID"
'connection stuff
Dim conn As OleDbConnection = New OleDbConnection(strConn)
conn.Open()
'command Object to Execute the SQL
Dim cmd As OleDbCommand = New OleDbCommand(strUpdateSql, conn)
cmd.Parameters.Add(New OleDbParameter("@name", txtName.text))
cmd.Parameters.Add(New OleDbParameter("@Status", txtStatus.text))
cmd.Parameters.Add(New OleDbParameter("@Action", txtAction.text))
cmd.Parameters.Add(New OleDbParameter("@Staff", txtStaff.text))
cmd.Parameters.Add(New OleDbParameter("@ProjectID",
CType(e.Item.Cells(0).Text, Long)))
cmd.ExecuteNonQuery()
'do housekeeping
DataGrid1.EditItemIndex = -1
conn.close
'rebind
BindData()
End Sub