Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Casting from CLR types to SQL types

Author  Topic 

rtutus
Aged Yak Warrior

522 Posts

Posted - 2006-06-25 : 00:47:40
1/ When my textbox is empty, doing:
pm=Mysqlcommand.parameters.add(new sqlparameter("@Address",sqldbtype.char,50))
pm.value=Mytextbox.text

sends a string with empty spaces to my table in SQL server.
The way I avoid that I do:

if Mytextbox.text=string.empty then
pm.value=sqlstring.null
else
pm.value=Mytextbox.text
end if

My Question: I want to do that automatically with only one instruction and without doing If...then..else....

2/ How to cast string variables to sqlstring like from MyTextBox.text to a sqlstring type
3/ Sometimes, my object : Myobject is not set to an instance, but I still want to assign it to my parameter
pm.value=MyObject.property
Is that possible

4/ Do u know hoe to cast other types: Integer to SqlInt64 and vice versa;

Thanks a lot

JBelthoff
Posting Yak Master

173 Posts

Posted - 2006-06-26 : 11:09:08
1. You are going to have to do the If..Then either in Asp.Net or in the Database.


If Mytextbox.text.trim = "" Then
pm.value = dbNull
Else
pm.value = Mytextbox.text.trim
End If


2. Use the ADO.Net Command Object.
3. If your object is not set to an instance, your code will more than likely fail.
4. Use the ADO.Net Command Object.




JBelthoff
• Hosts Station is a Professional Asp Hosting Provider
• Position SEO can provide your company with SEO Services at an affordable price
› As far as myself... I do this for fun!
Go to Top of Page
   

- Advertisement -