473,799 Members | 3,298 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 DataGridCommand EventArgs )
'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(st rUpdateSql, 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.Ce lls(0).Text, Long)))
cmd.ExecuteNonQ uery()

'do housekeeping
DataGrid1.EditI temIndex = -1
conn.close

'rebind
BindData()
End Sub
Nov 17 '05 #1
3 7690
Hi Russ,

You need to use the last parameter @product ID

cmd.Parameters. Add(New OleDbParameter( "@ProjectID ",
DataGrid1.DataK eys(e.Item.Item Index))

It's interesting your sub is

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

"Russ Green" <ru**********@h otmail.com> wrote in message
news:ew******** ******@TK2MSFTN GP12.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 DataGridCommand EventArgs )
'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(st rUpdateSql, 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.Ce lls(0).Text, Long)))
cmd.ExecuteNonQ uery()

'do housekeeping
DataGrid1.EditI temIndex = -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.Ole Db.OleDbExcepti on: Operation must use an updateable query. at
System.Data.Ole Db.OleDbCommand .ExecuteCommand TextErrorHandli ng(Int32 hr) at
System.Data.Ole Db.OleDbCommand .ExecuteCommand TextForSingleRe sult(tagDBPARAM S
dbParams, Object& executeResult) at
System.Data.Ole Db.OleDbCommand .ExecuteCommand Text(Object& executeResult) at
System.Data.Ole Db.OleDbCommand .ExecuteCommand (CommandBehavio r behavior,
Object& executeResult) at
System.Data.Ole Db.OleDbCommand .ExecuteReaderI nternal(Command Behavior
behavior, String method) at System.Data.Ole Db.OleDbCommand .ExecuteNonQuer y()
at ASP.db_project_ list_aspx.DataG rid_Update(Obje ct s,
DataGridCommand EventArgs e) in D:\Web Design
Work\SALT_INTRA NET\asp_net\db_ project_list.as px:line 68

Any Ideas?

Russ

"John Toop" <jt***@rogers.c om> wrote in message
news:e$******** ******@TK2MSFTN GP10.phx.gbl...
Hi Russ,

You need to use the last parameter @product ID

cmd.Parameters. Add(New OleDbParameter( "@ProjectID ",
DataGrid1.DataK eys(e.Item.Item Index))

It's interesting your sub is

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

"Russ Green" <ru**********@h otmail.com> wrote in message
news:ew******** ******@TK2MSFTN GP12.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 DataGridCommand EventArgs )
'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(st rUpdateSql, 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.Ce lls(0).Text, Long)))
cmd.ExecuteNonQ uery()

'do housekeeping
DataGrid1.EditI temIndex = -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**********@h otmail.com> wrote in message news:ul******** ******@TK2MSFTN GP12.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.Ole Db.OleDbExcepti on: Operation must use an updateable query. at
System.Data.Ole Db.OleDbCommand .ExecuteCommand TextErrorHandli ng(Int32 hr) at
System.Data.Ole Db.OleDbCommand .ExecuteCommand TextForSingleRe sult(tagDBPARAM S
dbParams, Object& executeResult) at
System.Data.Ole Db.OleDbCommand .ExecuteCommand Text(Object& executeResult) at
System.Data.Ole Db.OleDbCommand .ExecuteCommand (CommandBehavio r behavior,
Object& executeResult) at
System.Data.Ole Db.OleDbCommand .ExecuteReaderI nternal(Command Behavior
behavior, String method) at System.Data.Ole Db.OleDbCommand .ExecuteNonQuer y()
at ASP.db_project_ list_aspx.DataG rid_Update(Obje ct s,
DataGridCommand EventArgs e) in D:\Web Design
Work\SALT_INTRA NET\asp_net\db_ project_list.as px:line 68

Any Ideas?

Russ

"John Toop" <jt***@rogers.c om> wrote in message
news:e$******** ******@TK2MSFTN GP10.phx.gbl...
Hi Russ,

You need to use the last parameter @product ID

cmd.Parameters. Add(New OleDbParameter( "@ProjectID ",
DataGrid1.DataK eys(e.Item.Item Index))

It's interesting your sub is

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

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

"Russ Green" <ru**********@h otmail.com> wrote in message
news:ew******** ******@TK2MSFTN GP12.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 DataGridCommand EventArgs )
'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(st rUpdateSql, 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.Ce lls(0).Text, Long)))
cmd.ExecuteNonQ uery()

'do housekeeping
DataGrid1.EditI temIndex = -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
5677
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 itemtemplate. Datagrid is something like this- Category Week Amt Week% Button Revenue 1 100 Update Revenue 2 200 Update Cost 1 25 25
3
2222
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 make the changes and click Update, it reverts back to the old value. I'm stumped! I've also checked the db table and it is infact not updating. I'm attempting to follow and example right out of ASP.NET Unleashed but not having much luck. Any...
4
2977
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 linkbuttons which must not cause validation. I have found a setting "causeValidation" to disable the validation. Also on the page, I have a datagrid that I will edit lines on. I can click
25
4076
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
13
2672
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. My probelm.... when I have the user press the update button (which does a post back that loops through the datagrid and updates a database) the field/cell that is filled by the javascript appears to be blank in my update code, even though I can...
4
2151
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 SQL database "pubs". I've followed the instructions in the comments and also changed everything pertaining to SQL over to OLEDB. (i.e. Changed SqlDbType. to OleDbType.) I also changed the datafield names and variable names accordingly. The page...
3
1879
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 not there, of course. How do I get that field back into the datatable for the database update? TIA, Larry Woods
5
2600
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
6479
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 (FieldName-Authorised) which has a datatype bit through DataGrid but not sure how to go about it. Any Ideas Guys on this one, your help is greatly appreciated. This is the procedure used to populate the datagrid, The primary key for the table is EntryID which...
1
2299
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 and columns in a datagrid if there are number of rows and columns.so in my web page i have got two labels two textboxes and three buttons namely add update and delete so when i click on the add button the data is added to datagrid and also displayed...
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10260
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10030
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9078
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7570
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.