473,854 Members | 1,491 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Update records using datagrids

Dear all,

database use: Ms Access.
platform: .Net

i'm trying to update a record/records in a table called t_doctors by
clicking da edit link provided in the database.

when i ran through da browsers and click update it gave me this error:
Specified argument was out of the range of valid values. Parameter name:
index
I'm sorry, but i really couldn't think clearly right now, can someone
please help me out with this?
My updatedoctor.as px:
(the whole coding)

<%@ Page Language="vb" AutoEventWireup ="false"
Codebehind="doc torupdate.aspx. vb" Inherits="Clini c.doctorupdate" %>
<%@ import Namespace="syst em.data.oledb" %>
<%@ import Namespace="syst em.data" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Edit your data</title>
</HEAD>
<body bgColor="#99ccf f">
<p><font style="FONT-WEIGHT: 700; FONT-SIZE: 9pt" face="Tahoma">Y ou
are now in the
doctor profile. Please select what you would like to do with the
information.</font></p>
<table cellSpacing="0" cellPadding="0" width="151" border="0">
<tr>
<td width="151" background="ima ges/fon_menu.gif" height="30"><p
class="menu01" align="center"> <b><font style="FONT-SIZE: 9pt"
face="Tahoma">< A href="doctoradd .aspx">Add</A></font></b></p>
</td>
</tr>
<tr>
<td width="151" background="ima ges/fon_menu.gif" height="30"><p
class="menu01" align="center"> <b><font style="FONT-SIZE: 9pt"
face="Tahoma">U pdate</font></b></p>
</td>
</tr>
<tr>
<td width="151" background="ima ges/fon_menu.gif" height="30"><p
class="menu01" align="center"> <b><font style="FONT-SIZE: 9pt"
face="Tahoma">< A href="doctordel ete.aspx">Delet e</A></font></b></p>
</td>
</tr>
</table>
<p class="menu01" align="center"> <span style="Z-INDEX: 1; LEFT: 10px;
WIDTH: 681px; POSITION: absolute; TOP: 180px; HEIGHT: 3px; mso-ignore:
vglayout"><IMG height="3" src="../doctoradd_files/image001.gif"
width="681" v:shapes="_x000 0_s1025"></span></p>
<p class="menu01" align="center"> <IMG height="12" alt=""
src="images2/icon01.gif" width="11" align="absMiddl e"
border="0">&nbs p;&nbsp;<font style="FONT-WEIGHT: 700; FONT-SIZE: 9pt"
face="Tahoma">< A href="adminhome .html"><font
color="#000000" >HOME</font></A></font></p>
<p align="left"><f ont style="FONT-WEIGHT: 700; FONT-SIZE: 9pt"
face="Tahoma">P lease&nbsp;choo se
the&nbsp;record of the doctor's data to be updated:</font></p>
<form name="search_fo rm" runat="server" ID="Form1">
<P align="left">
<asp:datagrid id="dgdoctor" runat="server" Font-Names="Tahoma"
Font-Size="Smaller" Font-Name="Tahoma"
autogeneratecol umns="False" DataKeyField="d octor_id"
OnEditCommand=" SetEditMode" oncancelcommand ="CancelEdit "
OnUpdateCommand ="UpdateDatabas e">
<ItemStyle Font-Size="Smaller" Font-Names="Tahoma"
BackColor="#99c cFF"></ItemStyle>
<HeaderStyle Font-Bold="True" BackColor="#330 0FF"></HeaderStyle>
<Columns>
<asp:EditComman dColumn ButtonType="Lin kButton" UpdateText="Upd ate"
CancelText="Can cel" EditText="Edit" ></asp:EditCommand Column>
<asp:BoundColum n DataField="doct or_id" ReadOnly="True"
HeaderText="ID" ></asp:BoundColumn >
<asp:BoundColum n DataField="full name"
HeaderText="Nam e"></asp:BoundColumn >
<asp:BoundColum n DataField="nric " ReadOnly="True"
HeaderText="NRI C"></asp:BoundColumn >
<asp:BoundColum n DataField="date _of_birth" readonly="True"
HeaderText="Dat e of Birth"></asp:BoundColumn >
<asp:boundcolum n datafield="addr ess"
HeaderText="Add ress"></asp:boundcolumn >
<asp:boundcolum n datafield="nati onality"
HeaderText="Nat ionality"></asp:boundcolumn >
<asp:BoundColum n DataField="race " ReadOnly="True"
HeaderText="Rac e"></asp:BoundColumn >
<asp:BoundColum n DataField="qual ification"
HeaderText="Qua lification"></asp:BoundColumn >
</Columns>
</asp:datagrid></P>
</form>
</body>
</HTML>
--------------------------------------------------------
updatedoctor.as px:
(da datagrid part)

<form name="search_fo rm" runat="server" ID="Form1">
<P align="left">
<asp:datagrid id="dgdoctor" runat="server" Font-Names="Tahoma"
Font-Size="Smaller" Font-Name="Tahoma"
autogeneratecol umns="False" DataKeyField="d octor_id"
OnEditCommand=" SetEditMode" oncancelcommand ="CancelEdit "
OnUpdateCommand ="UpdateDatabas e">
<ItemStyle Font-Size="Smaller" Font-Names="Tahoma"
BackColor="#99c cFF"></ItemStyle>
<HeaderStyle Font-Bold="True" BackColor="#330 0FF"></HeaderStyle>
<Columns>
<asp:EditComman dColumn ButtonType="Lin kButton" UpdateText="Upd ate"
CancelText="Can cel" EditText="Edit" ></asp:EditCommand Column>
<asp:BoundColum n DataField="doct or_id" ReadOnly="True"
HeaderText="ID" ></asp:BoundColumn >
<asp:BoundColum n DataField="full name"
HeaderText="Nam e"></asp:BoundColumn >
<asp:BoundColum n DataField="nric " ReadOnly="True"
HeaderText="NRI C"></asp:BoundColumn >
<asp:BoundColum n DataField="date _of_birth" readonly="True"
HeaderText="Dat e of Birth"></asp:BoundColumn >
<asp:boundcolum n datafield="addr ess"
HeaderText="Add ress"></asp:boundcolumn >
<asp:boundcolum n datafield="nati onality"
HeaderText="Nat ionality"></asp:boundcolumn >
<asp:BoundColum n DataField="race " ReadOnly="True"
HeaderText="Rac e"></asp:BoundColumn >
<asp:BoundColum n DataField="qual ification"
HeaderText="Qua lification"></asp:BoundColumn >
</Columns>
</asp:datagrid></P>
</form>
---------------------------------------------------------
Enclosed is the code behind for updatedoctor.as px from page_load
downwards:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
If Not IsPostBack Then
BindDataGrid()
End If
End Sub

Sub BindDataGrid()
Dim myConn As OleDbConnection
Dim myOleDbAdapter As OleDbDataAdapte r
Dim connStr, sqlStr As String
Dim myDataSet As New DataSet

connStr = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source= " &
Server.MapPath( "clinic.mdb ")
sqlStr = "SELECT * FROM t_doctors ORDER BY doctor_id"
myConn = New OleDbConnection (connStr)
myConn.Open()
myOleDbAdapter = New OleDbDataAdapte r(sqlStr, myConn)
myOleDbAdapter. Fill(myDataSet, "t_doctors" )
dgdoctor.DataSo urce = myDataSet.Table s("t_doctors" )
dgdoctor.DataBi nd()
myConn.Close()
End Sub

Sub SetEditMode(ByV al s As Object, ByVal e As
DataGridCommand EventArgs) Handles dgdoctor.EditCo mmand
dgdoctor.EditIt emIndex = e.Item.ItemInde x
BindDataGrid()
End Sub

Sub CancelEdit(ByVa l s As Object, ByVal e As
DataGridCommand EventArgs) Handles dgdoctor.Cancel Command
dgdoctor.EditIt emIndex = -1
BindDataGrid()
End Sub

Sub UpdateDatabase( ByVal s As Object, ByVal e As
DataGridCommand EventArgs) Handles dgdoctor.Update Command
Dim myConn As OleDbConnection
Dim connStr, sqlStr, strFullname, strNric, strDob, strAddress,
strNationality, strRace, _
strQualificatio n As String
Dim myUpdateCommand As OleDbCommand
Dim intdoctorId As Integer

'get the key value of the row, here its da record id of the
database clinic.mdb of table t_doctors
intdoctorId = dgdoctor.DataKe ys.Item(e.Item. ItemIndex)

'get the new value for the respective fields
strFullname = (CType(e.Item.C ells(1).Control s(0), TextBox)).Text
strNric = (CType(e.Item.C ells(2).Control s(0), TextBox)).Text
strDob = (CType(e.Item.C ells(3).Control s(0), TextBox)).Text
strAddress = (CType(e.Item.C ells(4).Control s(0), TextBox)).Text
strNationality = (CType(e.Item.C ells(5).Control s(0),
TextBox)).Text
strRace = (CType(e.Item.C ells(6).Control s(0), TextBox)).Text
strQualificatio n = (CType(e.Item.C ells(7).Control s(0),
TextBox)).Text

sqlStr = "UPDATE t_doctors SET fullname='" + strFullname + "',
nric='" + strNric + "', date_of_birth = '" + strDob _
+ "', address = '" + strAddress + "', nationality='" +
strNationality + "', race='" + strRace _
+ "', qualification=' " + strQualificatio n + "' WHERE
doctor_id=intdo ctorId.ToString "

connStr = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source= " &
Server.MapPath( "clinic.mdb ")
myConn = New OleDbConnection (connStr)
myConn.Open()
myUpdateCommand = New OleDbCommand(sq lStr, myConn)
myUpdateCommand .ExecuteNonQuer y()
myConn.Close()
dgdoctor.EditIt emIndex = -1
BindDataGrid()

End Sub

----------------------------------------------------------

This part is da update part only:

Sub UpdateDatabase( ByVal s As Object, ByVal e As
DataGridCommand EventArgs) Handles dgdoctor.Update Command
Dim myConn As OleDbConnection
Dim connStr, sqlStr, strFullname, strNric, strDob, strAddress,
strNationality, strRace, _
strQualificatio n As String
Dim myUpdateCommand As OleDbCommand
Dim intdoctorId As Integer

'get the key value of the row, here its da record id of the
database clinic.mdb of table t_doctors
intdoctorId = dgdoctor.DataKe ys.Item(e.Item. ItemIndex)

'get the new value for the respective fields
strFullname = (CType(e.Item.C ells(1).Control s(0), TextBox)).Text
strNric = (CType(e.Item.C ells(2).Control s(0), TextBox)).Text
strDob = (CType(e.Item.C ells(3).Control s(0), TextBox)).Text
strAddress = (CType(e.Item.C ells(4).Control s(0), TextBox)).Text
strNationality = (CType(e.Item.C ells(5).Control s(0),
TextBox)).Text
strRace = (CType(e.Item.C ells(6).Control s(0), TextBox)).Text
strQualificatio n = (CType(e.Item.C ells(7).Control s(0),
TextBox)).Text

sqlStr = "UPDATE t_doctors SET fullname='" + strFullname + "',
nric='" + strNric + "', date_of_birth = '" + strDob _
+ "', address = '" + strAddress + "', nationality='" +
strNationality + "', race='" + strRace _
+ "', qualification=' " + strQualificatio n + "' WHERE
doctor_id=intdo ctorId.ToString "

connStr = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source= " &
Server.MapPath( "clinic.mdb ")
myConn = New OleDbConnection (connStr)
myConn.Open()
myUpdateCommand = New OleDbCommand(sq lStr, myConn)
myUpdateCommand .ExecuteNonQuer y()
myConn.Close()
dgdoctor.EditIt emIndex = -1
BindDataGrid()

End Sub
*************** *************** *************** *********

can someone please help me figure this out.
I'm really out of time right now... and i just can't think anything.

Your help is greatly appreciated!

Best Regards,
mursyidah
p/s: you can send da solution to my email as above
or just in case its mu************* **@yahoo.com.sg
Thanks again!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #1
1 2029
Mursyidatum,

Why don't you make for yourself a simple program to do this with one
keyfield and a normal field.

When it than is not working, we can probably help you.
Now it is more unpaid consultancy work because ou are giving a probably
complete program.

One thing you surely would not do it using the + in VBNet where the & should
be used, althoug mostly it goes well, can that give a lot of problems.

Or even better use the OleDBCommandPar ameters for the update.

http://msdn.microsoft.com/library/de...eterstopic.asp

I hope however this helps a little bit.

Cor
Nov 21 '05 #2

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

Similar topics

2
3855
by: Reply via newsgroup | last post by:
Folks, When performing an update in mysql (using PHP), can I find out how many records were matched? mysql_affected_rows() won't work... and I have the following problem that I thought I could resolve with a simple function: Example: I have 50records - I want to update a selection of the recods - some,
1
3683
by: Google Mike | last post by:
I have one table of new records (tableA) that may already exist in tableB. I want to insert these records into tableB with insert if they don't already exist, or update any existing ones with new data if they do already exist. A column (Action) in tableA already tells me whether this is an INSERT, UPDATE, or DELETE. I'm able to derive that I can do an insert with select * into tableB from tableA where Action = 'INSERT' ....and I think...
2
2527
by: serge | last post by:
/* This is a long post. You can paste the whole message in the SQL Query Analyzer. I have a scenario where there are records with values pointing to wrong records and I need to fix them using an Update statement. I have a sample code to reproduce my problem. To simplify the scenario I am trying to use Order related tables to explain a little better the tables i have to work with.
16
17040
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums must be UPDATED, if not, they must be INSERTED. Logically then, I would like to SELECT * FROM <TABLE> WHERE ....<Values entered here>, and then IF FOUND UPDATE <TABLE> SET .... <Values entered here> ELSE INSERT INTO <TABLE> VALUES <Values...
3
1036
by: TM | last post by:
I have two datagrids in my application where one grid is for the master item list and the second grid is for a shopping list. I would like to click on a button and copy items from the master list to the shopping list. Both are tied to tables in the same access mdb file. How can I copy a record from one to the other ? Is there some where that I can find out how to work with the records in the data grids, such as saving them back to...
11
2259
by: Siv | last post by:
Hi, I seem to be having a problem with a DataAdapter against an Access database. My app deletes 3 records runs a da.update(dt) where dt is a data.Datatable. I then proceed to update a list to reflect that the 3 items have been deleted only to discover that the 3 items appear, however when I click on them to display their information which runs a datareader over the same database it appears that the data has now gone. I wondered whether...
16
3509
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record in a hidden field) I wish the user to be able to edit the data in the table, so I have extracted the records into hiddenfield, textareas, dropdown list and checkbox so that they can make changes. I named these elements as arrays and wish to run an...
16
3531
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for renaming the duplicate records? My thinking was to take the results of the duplicate query, and somehow have it number each line where there is a duplicate (tried a groups query, but "count" won't work), then do an update query to change the duplicate to...
6
4074
by: mukeshrasm | last post by:
Hi I want to update records in database based on selected records using checkbox. if user does not select a record and clicks update button it should show the message please select record to be update if user selects say 3 records then there should be message are you sure to update 3 records and when clicks ok records should get updated. since records are coming dynamically so how can I get the number of checkboxes selected or not to...
0
9751
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11024
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9512
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
7912
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
7079
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5939
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4556
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
4152
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.