ObjectDataSource has no values to insert error

  • Thread starter Thread starter siamesedream
  • Start date Start date
S

siamesedream

Hello,
I'm having trouble using the insert method of an ObjectDataSource that
uses a custom DataObjectType. If I'm using a custom DataObjectType does
my insert method have to take that object, i.e.
myInsertMethod(MyCustomObjectType foobar) or can I actually specify
parameters to the insert method via the InsertParameters collection
associated with the ObjectDataSource, i.e. myInsertMethod(string name,
int age). Doing the latter I keep getting the error message
ObjectDataSource has no values to insert. Check that the 'values'
dictionary contains values,

- Harry
 
Hello,
I'm having trouble using the insert method of an ObjectDataSource that
uses a custom DataObjectType. If I'm using a custom DataObjectType does
my insert method have to take that object, i.e.
myInsertMethod(MyCustomObjectType foobar) or can I actually specify
parameters to the insert method via the InsertParameters collection
associated with the ObjectDataSource, i.e. myInsertMethod(string name,
int age). Doing the latter I keep getting the error message
ObjectDataSource has no values to insert. Check that the 'values'
dictionary contains values,

- Harry

Hi Harry,

I've been asked this a bunch so I thought I write a blog about it. The
short answer is:

ObjectDataSource1.InsertParameters[“roleName”].DefaultValue =
TextBoxRole.Text;
ObjectDataSource1.Insert();

The Long answer is here: http://peterkellner.net/?p=37

Good Luck.
Peter Kellner
http://peterkellner.net
 
Thank you Peter, that does work, however, I was under the impression
that I could do something like this in my .aspx page and achieve the
same effect as the code you posted in your reply:

<InsertParameters>
<asp:ControlParameter Name="roleName" ControlID="roleNameTextBox"
PropertyName="Text" />
</InsertParameters>

The above doesn't work and generates the error message I described in
my original post. Why am I unable to accomplish the same task using a
ControlParameter?

- Harry
Hello,
I'm having trouble using the insert method of an ObjectDataSource that
uses a custom DataObjectType. If I'm using a custom DataObjectType does
my insert method have to take that object, i.e.
myInsertMethod(MyCustomObjectType foobar) or can I actually specify
parameters to the insert method via the InsertParameters collection
associated with the ObjectDataSource, i.e. myInsertMethod(string name,
int age). Doing the latter I keep getting the error message
ObjectDataSource has no values to insert. Check that the 'values'
dictionary contains values,

- Harry

Hi Harry,

I've been asked this a bunch so I thought I write a blog about it. The
short answer is:

ObjectDataSource1.InsertParameters["roleName"].DefaultValue =
TextBoxRole.Text;
ObjectDataSource1.Insert();

The Long answer is here: http://peterkellner.net/?p=37

Good Luck.
Peter Kellner
http://peterkellner.net
 
Thank you Peter, that does work, however, I was under the impression
that I could do something like this in my .aspx page and achieve the
same effect as the code you posted in your reply:

<InsertParameters>
<asp:ControlParameter Name="roleName" ControlID="roleNameTextBox"
PropertyName="Text" />
</InsertParameters>

The above doesn't work and generates the error message I described in
my original post. Why am I unable to accomplish the same task using a
ControlParameter?

- Harry

I'm thinking control parameters work on controls like gridview and
details view. not sure how you would tie it to a textbox. I'll think
on that.
Peter Kellner
http://peterkellner.net
 
Back
Top