ObjectDataSource has no values to insert error

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
 
P

PeterKellner

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
 
S

siamesedream

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
 
P

PeterKellner

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
 
Joined
Aug 23, 2006
Messages
3
Reaction score
0
DataObjectTypeName

I also had trouble inserting record, however, I found out after testing for a while and google a bit, that if your specify 'DataObjectTypeName' parameter in ObjectDataSource, InsertParameters get ignored. So I just don't specify that, and it works for me.
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top