Hi,
I want to initialize a class with data coming from a MySql db. Some fields can be null:
Dim dr As MySqlDataReader = ...
Dim item As New Item(dr.GetInt16(0), dr.GetString(1), dr.GetString(2))
Suppose the last two fields could be NULL In the db, so that calling GetString on that field causes an exception.
I could certainly write ...
I can check for a DBnull on a data row using any of the methods.
Either by using
if(dr[0][0]==DBNull.Value)
//do somethin
or by doing
if(dr[0][0].ToString().IsNullOrEmpty())
//do something
In Both Cases I will be getting same result.
But Which one is conecptually right approach. Which was will use less resources
...
I have defined Class Person property Birthday as nullable DateTime? , so why shouldn’t the null coalescing operator work in the following example?
cmd.Parameters.Add(new SqlParameter("@Birthday",
SqlDbType.SmallDateTime)).Value =
person.Birthday ?? DBNull.Value;
The compiler err I got was "Operator '??' cannot be appl...
Hey all,
It seems that there's some type confusion in the ternary operator. I know that this has been addressed in other SO threads, but it's always been with nullables. Also, for my case I'm really just looking for a better way.
I'd like to be able to use
proc.Parameters[PARAM_ID].Value =
string.IsNullOrEmpty(dest.Id) ? DBNull....
I have a Windows forms DataGridView with a combobox column. The combo box column is bound to a data source that is populated from a Linq to Entities query. I would like users to be able to select "Nothing" in the combo box (assign a value of NULL to the underlying data source).
How can I accomplish this?
...
I frequently have to deal with DataTables connected to grid controls, custom updating always seems to produce a lot of code related to DBNull.Value. I saw a similar question here but think there must be a better answer:
http://stackoverflow.com/questions/26809/what-is-the-best-way-to-deal-with-dbnulls
The thing I find is I tend to enca...
I'm making my first forays into Accessing Oracle from C#. I've discovered that that Oracle doesn't like VarChar parameters to have value of null (C#). I would have hoped that there would be some implicit conversion, but I appreciate the difference.
So I need to trap these null values and supply DBNull.Value instead, surely? The most obv...
I have a MaskedTextBox control with the mask "00/00/0000", the PromptChar "_" and the ValidatingType of DateTime, bound to a DateTime column in a database that can also accept null values.
I'd like the user to have to enter either a valid date, or leave it blank (i.e. "__/__/____") for a DBNull.
By using the TypeValidationCompleted eve...
I have created a Windows Search string custom property that shows up fine as a column in Windows Explorer. In C# I issue the following SQL query:
SELECT System.ItemPathDisplay, System.ItemName, My.Custom.Property FROM SystemIndex WHERE CONTAINS(My.CustomProperty, 'blah')
The resulting OleDbDataReader correctly returns a list of the fi...
Hi Guys,
Please can any one advise me if it is possible to decalre a custom structure that can be assigned Nothing and / or DbNull.Values, and also can be instanciated as Nothing?
What I am looking to do is ceate a custom DateTime object that can recieve a DBNull.Value from a database query and also start life as Nothing. IS this possi...
I have seen many, many versions of this on SO, but none of them seem to quite work for my needs.
My data comes from a vendor database that allows null for DateTime fields. First I pull my data into a DataTable.
using (SqlCommand cmd = new SqlCommand(sb.ToString(), conn))
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
da.Fil...
Hello.
I have the following table on Sqlite3 on Android:
Game
------
gameId
That it was created with the following script:
CREATE TABLE Game (gameId) INTEGER PRIMARY KEY AUTOINCREMENT);"
When I'm going to insert data on table I don't put a value for column gameId. Doing this I get the following error:
android.database.sqlite.SQLi...