Edit records and UPDATE statements

G

Guest

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
 
G

Guest

I have the "Edit" column (first column), then two additional Template columns
after that. The 4th column is the first field.

Antonio
 
G

gmiley

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
 
G

Guest

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 said:
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
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top