468,321 Members | 1,814 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,321 developers. It's quick & easy.

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 883
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 discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.