473,466 Members | 1,286 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 996
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
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,...
0
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...
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.