Insert Null

Posts   
 
    
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 14-Jul-2010 11:33:38   

LLBLGEN Version 3.0 LLBLGEN Runtime Framework .NET 2.0 Oracle 9i

Dear Support, Here is extract of my code for saveentity.

var affiliateclubadapter = new DataAccessAdapter(); var affiliateclub = new AffiliateclubEntity(); string returnAffiliateClubNo = ""; affiliateclub.Affiliateclubno = Convert.ToString(ActionProcedures.Getnextid(ref returnAffiliateClubNo)); affiliateclub.Name = ChangeCase.ToTitleCase(tbxname.Text); affiliateclub.Address = ChangeCase.ToTitleCase(tbxaddress1.Text + "$" + tbxaddress2.Text + "$" + tbxaddress3.Text + "$" + tbxaddress4.Text); affiliateclub.Pincode = Convert.ToInt32(tbxpincode.Text).ToString(); affiliateclub.CityId = Convert.ToInt32(cmbcityid.SelectedValue); affiliateclub.Cityother = ChangeCase.ToTitleCase(tbxcityother.Text); affiliateclub.CountryId = Convert.ToInt32(cmbcountryid.SelectedValue); affiliateclub.StateId = Convert.ToInt32(cmbstateid.SelectedValue); affiliateclub.Phonenumber1 = Convert.ToInt32(tbxphonenumber1.Text).ToString(); affiliateclub.Mobilenumber1 = Convert.ToInt32(tbxmobilenumber1.Text).ToString(); affiliateclub.Faxnumber1 = Convert.ToInt32(tbxfaxnumber1.Text).ToString(); affiliateclub.Emailid1 = ChangeCase.ToLowerCase(tbxemailid1.Text);

            affiliateclub.Effectivedatefrom =
                Convert.ToDateTime(ValidateDate.dateToString(dateeffectivedatefrom.Text));
            affiliateclub.Effectivedateto = Convert.ToDateTime(ValidateDate.dateToString(dateeffectivedateto.Text));

            affiliateclub.Createddate = ServerDateTime.getcurrentserverdatewithtime();
            affiliateclub.CreateduserId = StandardMessage.loginuserid;

Problem:

In UI, user did not enter Emailid1. In this case, I have to pass DBNull to Database. If user enters value, then value should be passed. But note sure how to alter this line

affiliateclub.Emailid1 = ChangeCase.ToLowerCase(tbxemailid1.Text); to achive the purpose.

I was able to manage for fetchentity with the help of documentation but in saveentity am not able to do so. Can you please give me the syntax.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 14-Jul-2010 12:55:01   

Don't set the affiliateclub.Emailid1 if there is no text written in the textBox.

shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 14-Jul-2010 14:06:10   

Walaa wrote:

Don't set the affiliateclub.Emailid1 if there is no text written in the textBox.

Do you mean to say I write to like this ?

if textbox is null..... then skip affiliateclub.Emailid1 else use affiliateclub.Emailid1. That means if I have 20 optional UI input, Do I have to write 20 if conditions to check for input and then insert?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 14-Jul-2010 14:18:30   

Yes. That's why it's recomended to use databinding.

shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 14-Jul-2010 15:51:01   

Walaa wrote:

Yes. That's why it's recomended to use databinding.

Ok. Assuming that i opt to use databinding for this entity, how can I over come this issue?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 14-Jul-2010 16:02:40   

This will be handled automaticaly.

shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 14-Jul-2010 16:13:36   

Walaa wrote:

This will be handled automaticaly.

If some user is using C# and without winform binding, they can write a small function like this

object GetDBValue(object value) { return value == null ? DBNull.Value : value; }

Thought of posting this, thinking it may help others if need be.