473,320 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Update from datagrid

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/ne...creenshot1.gif
The update button does nothing. See
http://www.russgreen.net/software/ne...creenshot2.gif

Error page
http://www.russgreen.net/software/ne...nUPDATEstateme
nt_.htm
..aspx page
http://www.russgreen.net/software/ne..._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
Nov 17 '05 #1
3 7664
Hi Russ,

You need to use the last parameter @product ID

cmd.Parameters.Add(New OleDbParameter("@ProjectID",
DataGrid1.DataKeys(e.Item.ItemIndex))

It's interesting your sub is

DataGrid_Update but the ID of the object seems to be DataGrid1. I would have
expected DataGrid1_UpdateCommand but I suppose that could just be the way
that datamatrix wires it up. Then again... perhaps I'm wrong.

"Russ Green" <ru**********@hotmail.com> wrote in message
news:ew**************@TK2MSFTNGP12.phx.gbl...
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/ne...creenshot1.gif
The update button does nothing. See
http://www.russgreen.net/software/ne...creenshot2.gif

Error page
http://www.russgreen.net/software/ne...nUPDATEstateme nt_.htm
.aspx page
http://www.russgreen.net/software/ne..._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

Nov 17 '05 #2
OK

I sorted it. Well almost. The attached page works on the Webmatrix testing
server but not on IIS. Under IIS the page render OK but UPDATE generate the
following exception: -

System.Data.OleDb.OleDbException: Operation must use an updateable query. at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHandling(Int32 hr) at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS
dbParams, Object& executeResult) at
System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object& executeResult) at
System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior behavior,
Object& executeResult) at
System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior
behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
at ASP.db_project_list_aspx.DataGrid_Update(Object s,
DataGridCommandEventArgs e) in D:\Web Design
Work\SALT_INTRANET\asp_net\db_project_list.aspx:li ne 68

Any Ideas?

Russ

"John Toop" <jt***@rogers.com> wrote in message
news:e$**************@TK2MSFTNGP10.phx.gbl...
Hi Russ,

You need to use the last parameter @product ID

cmd.Parameters.Add(New OleDbParameter("@ProjectID",
DataGrid1.DataKeys(e.Item.ItemIndex))

It's interesting your sub is

DataGrid_Update but the ID of the object seems to be DataGrid1. I would have expected DataGrid1_UpdateCommand but I suppose that could just be the way
that datamatrix wires it up. Then again... perhaps I'm wrong.

"Russ Green" <ru**********@hotmail.com> wrote in message
news:ew**************@TK2MSFTNGP12.phx.gbl...
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/ne...creenshot1.gif
The update button does nothing. See
http://www.russgreen.net/software/ne...creenshot2.gif

Error page

http://www.russgreen.net/software/ne...nUPDATEstateme
nt_.htm
.aspx page
http://www.russgreen.net/software/ne..._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


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.500 / Virus Database: 298 - Release Date: 10/07/2003


Nov 17 '05 #3
Hi Russ,
you are getting this error "Operation must use an updateable query" may for two reasons...
1. Folder where you are having MDB file doesnot have permission for your asp.net applications.
2. Give the permission for MDB file.

Rajeev

"Russ Green" <ru**********@hotmail.com> wrote in message news:ul**************@TK2MSFTNGP12.phx.gbl...
OK

I sorted it. Well almost. The attached page works on the Webmatrix testing
server but not on IIS. Under IIS the page render OK but UPDATE generate the
following exception: -

System.Data.OleDb.OleDbException: Operation must use an updateable query. at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHandling(Int32 hr) at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS
dbParams, Object& executeResult) at
System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object& executeResult) at
System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior behavior,
Object& executeResult) at
System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior
behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
at ASP.db_project_list_aspx.DataGrid_Update(Object s,
DataGridCommandEventArgs e) in D:\Web Design
Work\SALT_INTRANET\asp_net\db_project_list.aspx:li ne 68

Any Ideas?

Russ

"John Toop" <jt***@rogers.com> wrote in message
news:e$**************@TK2MSFTNGP10.phx.gbl...
Hi Russ,

You need to use the last parameter @product ID

cmd.Parameters.Add(New OleDbParameter("@ProjectID",
DataGrid1.DataKeys(e.Item.ItemIndex))

It's interesting your sub is

DataGrid_Update but the ID of the object seems to be DataGrid1. I would

have
expected DataGrid1_UpdateCommand but I suppose that could just be the way
that datamatrix wires it up. Then again... perhaps I'm wrong.

"Russ Green" <ru**********@hotmail.com> wrote in message
news:ew**************@TK2MSFTNGP12.phx.gbl...
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/ne...creenshot1.gif
The update button does nothing. See
http://www.russgreen.net/software/ne...creenshot2.gif

Error page

http://www.russgreen.net/software/ne...nUPDATEstateme
nt_.htm
.aspx page
http://www.russgreen.net/software/ne..._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




---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.500 / Virus Database: 298 - Release Date: 10/07/2003


Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Manish | last post by:
Hey folks I am having a weird problem in ASP .Net. My page is in C#. I have a datagrid, which populates based on selection in drop down box on ASP page. This datagrid has template textbox colum in...
3
by: D. Shane Fowlkes | last post by:
I have a Datagrid which in theory, should allow you to edit and update the records. I've stripped my test page down so that it's only attempting to update one field - "description". Yet when I...
4
by: David Colliver | last post by:
Hi all, I am having a slight problem that hopefully, someone can help me fix. I have a form on a page. Many items on the form have validation controls attached. Also on this form are...
25
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
13
by: Lyners | last post by:
I have a web page writen in ASP.NET that contains some javascript so that when a user presses a button, or edits a certain field in a datagrid, another cell in the datagrid is filled with a value....
4
by: Jonathan Upright | last post by:
Greetings to anyone who can help: I'm using WebMatrix to make ASP.NET pages, and I chose the "Editable DataGrid" at the project selector screen. As you may know, it defaults to the Microsoft...
3
by: Larry Woods | last post by:
I have a datagrid that is carrying all fields of a record...except one. Now I want to update the underlying database via a dataadapter. The update is working but the field that is "left out" is...
5
by: Stephen Plotnick | last post by:
I'm very new to VB.NET 2003 Here is what I have accomplished: MainSelectForm - Selects an item In a public class I pass a DataViewRow to ItemInformation1 Form ItemInformation2 Form
1
by: Sharon | last post by:
Hello All, Is it possible to update Sql Table through DataGrid. I have a DataGrid which is being populated through a stored procedure, all i wanted to do is to update one field...
1
by: geeteshss | last post by:
Dear all, actually i spent a whole month on the R&D of datagrid edit ,update,cancel events but recently my guide told me to make it user friendly because no user would like to go on searching rows...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.