Connecting Tech Pros Worldwide Forums | Help | Site Map

Set message subject here ...

pjarvis@man.ac.uk
Guest
 
Posts: n/a
#1: Feb 13 '07
Hi guys,

Say for example i have a hypothetical function taking 4 parameters such as the one below:

public void InsertRow(char gender, double decimalAge, double height, double weight)
{
//Adds data into a MySQL database
}

If i have a piece of data missing such as height, but i still want to call the function that will add the other parameters into the database, how would i do it? I'd like to pass
a 'null' to the function, is there any way of achieving this without getting compiler errors?

Thanks in advance

Paul


--
--------------------------------- --- -- -
Posted with NewsLeecher v3.8 Final
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -


=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
 
Posts: n/a
#2: Feb 13 '07

re: Set message subject here ...


The general idea would be to pass either null, or System.DbNull.Value, or
whatever default value, handle such parameters inside the body of your
method, and go ahead and do your insert to your database.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net




"Paul C. Jarvis" wrote:
Quote:
Hi guys,
>
Say for example i have a hypothetical function taking 4 parameters such as the one below:
>
public void InsertRow(char gender, double decimalAge, double height, double weight)
{
//Adds data into a MySQL database
}
>
If i have a piece of data missing such as height, but i still want to call the function that will add the other parameters into the database, how would i do it? I'd like to pass
a 'null' to the function, is there any way of achieving this without getting compiler errors?
>
Thanks in advance
>
Paul
>
>
--
--------------------------------- --- -- -
Posted with NewsLeecher v3.8 Final
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -
>
>
PokerMan
Guest
 
Posts: n/a
#3: Feb 13 '07

re: Set message subject here ...


As Peter said the actual db addition of a null would be System.DbNull.

But i am guessing you want to also know how to make your method allow null
parameter values?

if so its like this

public void InsertRow(char gender, double? decimalAge, double? height,
double? weight)
{
//Adds data into a MySQL database
}

the ? after double, double? or with an int, int? just means it can have a
null value. When inserting that null into db use the System.DbNull.



"Paul C. Jarvis" <pjarvis@man.ac.ukwrote in message
news:Za-dnRifyeRpk0zYRVnyuQA@giganews.com...
Quote:
Hi guys,
>
Say for example i have a hypothetical function taking 4 parameters such as
the one below:
>
public void InsertRow(char gender, double decimalAge, double height,
double weight)
{
//Adds data into a MySQL database
}
>
If i have a piece of data missing such as height, but i still want to call
the function that will add the other parameters into the database, how
would i do it? I'd like to pass
a 'null' to the function, is there any way of achieving this without
getting compiler errors?
>
Thanks in advance
>
Paul
>
>
--
--------------------------------- --- -- -
Posted with NewsLeecher v3.8 Final
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -
>

susiedba@hotmail.com
Guest
 
Posts: n/a
#4: Feb 14 '07

re: Set message subject here ...


don't allow nulls in any database it makes your life a lot easier

use ZERO instead




On Feb 12, 5:05 pm, Paul C. Jarvis (pjar...@man.ac.uk) wrote:
Quote:
Hi guys,
>
Say for example i have a hypothetical function taking 4 parameters such as the one below:
>
public void InsertRow(char gender, double decimalAge, double height, double weight)
{
//Adds data into a MySQL database
>
}
>
If i have a piece of data missing such as height, but i still want to call the function that will add the other parameters into the database, how would i do it? I'd like to pass
a 'null' to the function, is there any way of achieving this without getting compiler errors?
>
Thanks in advance
>
Paul
>
--
--------------------------------- --- -- -
Posted with NewsLeecher v3.8 Final
Web @http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -

susiedba@hotmail.com
Guest
 
Posts: n/a
#5: Feb 14 '07

re: Set message subject here ...


C# does not support optional parameters

I would make sure that you don't use NULLs anywhere


On Feb 12, 5:05 pm, Paul C. Jarvis (pjar...@man.ac.uk) wrote:
Quote:
Hi guys,
>
Say for example i have a hypothetical function taking 4 parameters such as the one below:
>
public void InsertRow(char gender, double decimalAge, double height, double weight)
{
//Adds data into a MySQL database
>
}
>
If i have a piece of data missing such as height, but i still want to call the function that will add the other parameters into the database, how would i do it? I'd like to pass
a 'null' to the function, is there any way of achieving this without getting compiler errors?
>
Thanks in advance
>
Paul
>
--
--------------------------------- --- -- -
Posted with NewsLeecher v3.8 Final
Web @http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -

Closed Thread