TechTalkz.com Logo

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Programing Languages > C#(C Sharp)

Notices

Reply
 
Thread Tools Display Modes
Old 14-12-2007, 10:33 PM   #1
william.oram@gmail.com
Guest
 
Posts: n/a
'There is no row at position 0'

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!
  Reply With Quote
Old 15-12-2007, 02:27 AM   #2
william.oram@gmail.com
Guest
 
Posts: n/a
Re: 'There is no row at position 0'

On Dec 14, 10:29 am, "Mythran" <kip_pot...@hotmail.com> wrote:
> <william.o...@gmail.com> wrote in message
>
> news:d091874a-c785-4300-9be1-bfac94a0ebe4@i29g2000prf.googlegroups.com...
>
>
>
> > 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


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");
  Reply With Quote
Reply

Thread Tools
Display Modes


Google
 


All times are GMT +5.5. The time now is 05:44 AM.


vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2008, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional