Database ,New User,Last view

Posted by Raja_89 under C# on 10/11/2013 | Points: 10 | Views : 854 | Status : [Member] | Replies : 4
Hai
In my login whenever user login in into his account last view date[[Last Login Date]] will be shown
If the user register the present day he will not having the value for the last view date[Last Login Date]

How can i check the field is empty [ i have checked ISDBNULL ] is there any other idea
If it new user i will display the text "Just Now"


Kindly explain with an example

Regards




Responses

Posted by: Bandi on: 10/11/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
1) http://stackoverflow.com/questions/2017533/best-way-to-check-if-column-returns-a-null-value-from-database-to-net-applicat

2) we can just compare with null (or use the HasValue property) to see whether a "real" value has been set.
http://stackoverflow.com/questions/305154/checking-to-see-if-a-datetime-variable-has-had-a-value-assigned

3) http://stackoverflow.com/questions/8985854/datetime-as-empty-string-or-null-how-to-check

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Raja_89, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 10/11/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
http://forums.codeguru.com/showthread.php?434096-check-if-a-datetime-is-null

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Raja_89, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 10/11/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
sample code which is working ( Checking for DATATIME field for Nulls )
Use if( ObjWhichContainsDateValue.Equals(DBNull.Value)) for checking NULLs against Datetime

string connectionstring = "Data source=XXXX; Initial Catalog=DBName; Integrated Security=true";
SqlConnection conn = new SqlConnection(connectionstring);
conn.Open();
SqlCommand comm = new SqlCommand("SELECT [inactivate_ts] FROM [ADTool].[dbo].[Bus_Package] WHERE [bus_package_id] = " + txtBox.Text + ";", conn);
SqlDataAdapter da = new SqlDataAdapter(comm);
DataSet ds = new DataSet();
da.Fill(ds);

if (ds.Tables[0].Rows.Count != 0)
{
if (ds.Tables[0].Rows[0][0].Equals(DBNull.Value))
{
Label1.Text = "Just Now"; //1st row and 1st column
}
else
{
string str = DateTime.Parse(ds.Tables[0].Rows[0][0].ToString()).ToString("MM-dd-yyyy HH:m:ss");
Label1.Text = str;
}
}


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Raja_89, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 10/11/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Click on "Mark as Answer " if you solved the issue; Otherwise let us the know back

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Raja_89, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response