Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RadioButtonList Question 1

Status
Not open for further replies.

AppzDev

MIS
Oct 9, 2002
57
US
I'm trying to run an insert into statement into a SQL database and everything updates except when i include the radiobuttonlist in the insert statement. If i take it out, it works. I am getting a system.nullreferenceexception which i *think* means that it cannot insert a null into that field?? I know the SQL side accepts nulls for this field too. If either "Yes" or "No" are selected, the insert works fine, only when NEITHER is selected.

I am using the standard "INSERT INTO table (field1...)
VALUES @field1...."& radiobutton.selecteditem.text &" I've also tried radiobutton.selecteditem.value and that didn't work either...

So, i guess my question is...if there is NOTHING checked for the 2 items in my radiobuttonlist, why am i getting a nullreference error?? Anyone know how to resolve this?

Thanks again!

dc~
 
Null reference exception is not a SQL error, it's a VB error.

radiobutton.selecteditem.text

So if there's nothing selected, then

radiobutton.selecteditem

returns NULL (nothing selected), and .Text throws the error since NULL doesn't have a .Text property.

If there had been somthing selected, then .SelectedItem would have returned an object of type ListItem, which does have a .Text property, and hence... no error.

So, a better way might be to first see if something has been selected, and if so, insert the .Text, and if not, manually insert a 'NULL' into the database.

The object won't do it for you.

:)
paul
penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
Paul,

wow, thanks for the help on this. I fully understand your explanation! Now, i just have to figure out the code to do it...yes, i'm still an asp n00b. But, thanks to this forum, i'm getting better and learning a great deal! thanks!

dc~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top