'There is no row at position 0'

W

william.oram

I have a DataGrid and am attempting to have in-grid data editing. At
the moment I'm working with a single DropDownList:

public void roleList_Update(Object sender,
DataGridCommandEventArgs e)
{
int newRoleID = 666;

DropDownList ddl = (DropDownList)
e.Item.FindControl("ddlRoleEdit");

if (ddl != null)

newRoleID = int.Parse(ddl.SelectedValue);


roleListRowSQLAdapter.SelectCommand.Parameters["@currentRow"].Value =
(int) roleList.DataKeys[e.Item.ItemIndex];

roleListRowSQLAdapter.Fill(roleListRowDataSet);

roleListRowDataSet.ContactRoleDetailRow crd =
roleListRowDataSet.ContactRoleDetail[0]; /* BOOM! */
crd.Role = ddl.SelectedValue;
roleListRowSQLAdapter.Update(roleListRowDataSet.Co
ntactRoleDetail);
}



The commented line above is where the code breaks; the page complains
that 'There is no row at position 0.' Now, I understand this to mean
rowListRowDataSet is empty. But why? It was generated from an SQL
adapter and a SELECT statement I'm sure works. The parameter
@currentRow is valid, too. Isn't the 'Generate Dataset...' command all
that's needed to make a functioning DataSet? I'm picking this stuff up
by myself, so I may be missing some crucial idea.

Thanks!
 
M

Mythran

I have a DataGrid and am attempting to have in-grid data editing. At
the moment I'm working with a single DropDownList:

public void roleList_Update(Object sender,
DataGridCommandEventArgs e)
{
int newRoleID = 666;

DropDownList ddl = (DropDownList)
e.Item.FindControl("ddlRoleEdit");

if (ddl != null)

newRoleID = int.Parse(ddl.SelectedValue);


roleListRowSQLAdapter.SelectCommand.Parameters["@currentRow"].Value =
(int) roleList.DataKeys[e.Item.ItemIndex];

roleListRowSQLAdapter.Fill(roleListRowDataSet);

roleListRowDataSet.ContactRoleDetailRow crd =
roleListRowDataSet.ContactRoleDetail[0]; /* BOOM! */
crd.Role = ddl.SelectedValue;
roleListRowSQLAdapter.Update(roleListRowDataSet.Co
ntactRoleDetail);
}



The commented line above is where the code breaks; the page complains
that 'There is no row at position 0.' Now, I understand this to mean
rowListRowDataSet is empty. But why? It was generated from an SQL
adapter and a SELECT statement I'm sure works. The parameter
@currentRow is valid, too. Isn't the 'Generate Dataset...' command all
that's needed to make a functioning DataSet? I'm picking this stuff up
by myself, so I may be missing some crucial idea.

Thanks!

Well, there are a couple of things to try. What I would suggest is that you
perform a debug run and step through each line in that code to verify all
the values you expect are indeed the values being used (for example,
ddl.SelectedValue). Something I don't see is the code you use to create the
data adapter....that could have something to do with it as well, but we
can't tell because you didn't include it.

HTH,
Mythran
 
W

william.oram

I have a DataGrid and am attempting to have in-grid data editing. At
the moment I'm working with a single DropDownList:
public void roleList_Update(Object sender,
DataGridCommandEventArgs e)
{
int newRoleID = 666;
DropDownList ddl = (DropDownList)
e.Item.FindControl("ddlRoleEdit");
if (ddl != null)
newRoleID = int.Parse(ddl.SelectedValue);
roleListRowSQLAdapter.SelectCommand.Parameters["@currentRow"].Value =
(int) roleList.DataKeys[e.Item.ItemIndex];
roleListRowSQLAdapter.Fill(roleListRowDataSet);

roleListRowDataSet.ContactRoleDetailRow crd =
roleListRowDataSet.ContactRoleDetail[0]; /* BOOM! */
crd.Role = ddl.SelectedValue;
roleListRowSQLAdapter.Update(roleListRowDataSet.Co
ntactRoleDetail);
}
The commented line above is where the code breaks; the page complains
that 'There is no row at position 0.' Now, I understand this to mean
rowListRowDataSet is empty. But why? It was generated from an SQL
adapter and a SELECT statement I'm sure works. The parameter
@currentRow is valid, too. Isn't the 'Generate Dataset...' command all
that's needed to make a functioning DataSet? I'm picking this stuff up
by myself, so I may be missing some crucial idea.

Well, there are a couple of things to try. What I would suggest is that you
perform a debug run and step through each line in that code to verify all
the values you expect are indeed the values being used (for example,
ddl.SelectedValue). Something I don't see is the code you use to create the
data adapter....that could have something to do with it as well, but we
can't tell because you didn't include it.

HTH,
Mythran

Debugging is broken at the moment, but sending values to labels has
always worked for me. Prior to posting I had checked the most
important values: SelectCommand, @currentRow.Value, and SelectedValue,
and they all look good.

As for DataAdapter code, there really isn't much because it was
created with the Toolbox -> Data -> SQLDataAdapter object in Design
view. The code VS creates for the DA:

this.roleListRowSQLAdapter.SelectCommand = this.getCurrentRole;
this.roleListRowSQLAdapter.TableMappings.AddRange(new
System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "Program", new
System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("ID", "ID"),
new System.Data.Common.DataColumnMapping("Name", "Name"),
new System.Data.Common.DataColumnMapping("ShortName", "ShortName")
}
)});

And for the data set spawned from the DA:

this.roleListRowDataSet.DataSetName = "roleListRowDataSet";
this.roleListRowDataSet.Locale = new
System.Globalization.CultureInfo("en-US");
 

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