472,982 Members | 2,680 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Edit records and UPDATE statements

When I try to update a record, I get:

Specified argument was out of the range of valid values. Parameter name:
index

Exception Details: System.ArgumentOutOfRangeException: Specified argument
was out of the range of valid values. Parameter name: index

Source Error:

Line 133: SqlCommand updCommand = new SqlCommand();
Line 134: updCommand.Connection = conn;
Line 135: updCommand.CommandText = "UPDATE GEM.customers SET name = '"
Line 136: + ((TextBox)e.Item.Cells[6].Controls[0]).Text
Line 137: + "', address = '"

and the UPDATE line is selected. Can someone tell me what the error means?

Thanks,
Antonio
Jun 2 '06 #1
3 981
I have the "Edit" column (first column), then two additional Template columns
after that. The 4th column is the first field.

Antonio

"Antonio" wrote:
When I try to update a record, I get:

Specified argument was out of the range of valid values. Parameter name:
index

Exception Details: System.ArgumentOutOfRangeException: Specified argument
was out of the range of valid values. Parameter name: index

Source Error:

Line 133: SqlCommand updCommand = new SqlCommand();
Line 134: updCommand.Connection = conn;
Line 135: updCommand.CommandText = "UPDATE GEM.customers SET name = '"
Line 136: + ((TextBox)e.Item.Cells[6].Controls[0]).Text
Line 137: + "', address = '"

and the UPDATE line is selected. Can someone tell me what the error means?

Thanks,
Antonio

Jun 2 '06 #2
First, I would suggest that you handle your Command string building a
bit differently. As you have it right now, I have no clue what
e.Item.Cells[6] is, other than it possibly being a control of some
kind.

I would suggest to help narrow down where the error might be, break
that all up to look like this:

object cell = e.Item.Cells[6];
TextBox txtBox = (TextBox)cell.Controls[0];
string nameValue = txtBox.Text;

That still is a bit goofy. Can you provide me with what those things
are?

What is 'e' and what is its Type?
What is 'Item' and what is its Type?
What is 'Cells' and what is its Type?

Something in there isn't right.

gm

Antonio wrote:
When I try to update a record, I get:

Specified argument was out of the range of valid values. Parameter name:
index

Exception Details: System.ArgumentOutOfRangeException: Specified argument
was out of the range of valid values. Parameter name: index

Source Error:

Line 133: SqlCommand updCommand = new SqlCommand();
Line 134: updCommand.Connection = conn;
Line 135: updCommand.CommandText = "UPDATE GEM.customers SET name = '"
Line 136: + ((TextBox)e.Item.Cells[6].Controls[0]).Text
Line 137: + "', address = '"

and the UPDATE line is selected. Can someone tell me what the error means?

Thanks,
Antonio


Jun 2 '06 #3
Thank you for replying.

e is System.Web.UI.WebControls.DataGridCommandEventArgs as it is in the
procedure name: private void updateRow(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)

The connection string is in the web.config file and connects to the sql
server with the provided login.

The SQL string is:
dataCommand.CommandText = "SELECT GEM.customers.cust_id, " +
"GEM.customers.CustomerSince AS [Customer Since], " +
"GEM.customers.name AS [Insititution Name], " +
"GEM.contacts.name_first AS [First Name], " +
"GEM.contacts.name_last AS [Last Name], " +
"GEM.contacts.email AS [E-Mail Address], " +
"GEM.customers.address_1 AS Address, GEM.customers.city AS City, " +
"GEM.customers.state AS State, GEM.customers.zip_code AS [Zip Code], " +
"GEM.customers.postal_code AS [Postal Code], " +
"GEM.customers.country AS Country, GEM.customers.phone AS Phone " +
"FROM GEM.customers INNER JOIN GEM.config_usernames ON " +
"GEM.customers.cust_id = GEM.config_usernames.cust_id INNER JOIN " +
"GEM.contacts ON GEM.config_usernames.contact_id =
GEM.contacts.contact_id ORDER BY GEM.customers.name";

So, my understanding is that cell[6] as you see it in the UPDATE statement
refers to the GEM.customers.name column.
"gmiley" wrote:
First, I would suggest that you handle your Command string building a
bit differently. As you have it right now, I have no clue what
e.Item.Cells[6] is, other than it possibly being a control of some
kind.

I would suggest to help narrow down where the error might be, break
that all up to look like this:

object cell = e.Item.Cells[6];
TextBox txtBox = (TextBox)cell.Controls[0];
string nameValue = txtBox.Text;

That still is a bit goofy. Can you provide me with what those things
are?

What is 'e' and what is its Type?
What is 'Item' and what is its Type?
What is 'Cells' and what is its Type?

Something in there isn't right.

gm

Antonio wrote:
When I try to update a record, I get:

Specified argument was out of the range of valid values. Parameter name:
index

Exception Details: System.ArgumentOutOfRangeException: Specified argument
was out of the range of valid values. Parameter name: index

Source Error:

Line 133: SqlCommand updCommand = new SqlCommand();
Line 134: updCommand.Connection = conn;
Line 135: updCommand.CommandText = "UPDATE GEM.customers SET name = '"
Line 136: + ((TextBox)e.Item.Cells[6].Controls[0]).Text
Line 137: + "', address = '"

and the UPDATE line is selected. Can someone tell me what the error means?

Thanks,
Antonio


Jun 2 '06 #4

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

Similar topics

25
by: dixie | last post by:
I have some code that adds new records into a table for each ID in a list box when a button on a form is clicked. This works fine. My problem now is that I wish to be able to edit all the records...
3
by: pmud | last post by:
Hi, I have an ASP.NET application using C# code. I am using a datagrid to display records from a database based on a user input, i.e a user enters a compnay name in text box & when he clicks a...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
5
by: developing | last post by:
Hello, Hows it going people....so...its this annoying msg: Data has been changed Another user changed record and saved them before you. Re-edit the record "Another user" is me clicking...
2
by: David | last post by:
Dear All I'm trying to use a multi-select listbox as criteria to either add new record or edit the current record of the destiantation table with each row selected in the box. This works fine...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.