| | |
conversion of datetime when data is NULL
Please support our MS SQL advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2009
Posts: 13
Reputation:
Solved Threads: 0
hi friends fetching datetime values from database, when data is null in code side it is displying the some garbage value instead that i want to show 'date is not found' the result is showind in grid view control
service written for fetching datetime
service written for fetching datetime
C# Syntax (Toggle Plain Text)
public List<Topics> GetAllTopicNames(int communityId) { List<Topics> communityTopiclist = new List<Topics>(); try { string connectionString = ConfigurationSettings.AppSettings["connectionString"]; SqlConnection con = new SqlConnection(connectionString); con.Open(); SqlCommand cmd = new SqlCommand("SELECT * from (select cd.Community_id,ct.Topic_id ,ct.Name,ct.Posts from Community_Details cd,Community_Topic_Details ct where ct.Community_Id = cd.Community_Id ) as C left join (select cr.topic_id , max(cr.reply_date) as RecentPost from Community_Topic_Details ctr,Community_Replys cr where ctr.topic_id=cr.topic_id group by cr.topic_id) as rep on rep .topic_Id=c.Topic_Id where C.Community_id=" + communityId.ToString(), con); SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows != false) { while (dr.Read()) { Topics communityTopics = new Topics(); if (dr["Topic_Id"] != System.DBNull.Value) communityTopics.TopicId = int.Parse(dr["Topic_Id"].ToString()); if (dr["Name"] != System.DBNull.Value) communityTopics.TopicName = dr["Name"].ToString(); if (dr["Posts"] != System.DBNull.Value) communityTopics.TopicPosts = int.Parse(dr["Posts"].ToString()); if (dr["RecentPost"] != System.DBNull.Value) communityTopics.LastPost = DateTime.Parse(dr["RecentPost"].ToString()); communityTopiclist.Add(communityTopics); } } else { return null; } } catch (Exception ex) { return null; } return communityTopiclist; } public void GetAllTopics() { CommunityManagement.CommunityManagementSoap topicService = new CommunityManagement.CommunityManagementSoapClient(); GetAllTopicNamesRequest topicRequest = new GetAllTopicNamesRequest(); topicRequest.Body = new GetAllTopicNamesRequestBody(); topicRequest.Body.communityId = int.Parse(Request.QueryString["communityId"]); GetAllTopicNamesResponse topicResponse = topicService.GetAllTopicNames(topicRequest); if (topicResponse != null && topicResponse.Body != null && topicResponse.Body.GetAllTopicNamesResult != null) { GridViewCommunityTopics.DataSource = topicResponse.Body.GetAllTopicNamesResult; GridViewCommunityTopics.DataBind(); PanelMiddle.Controls.Add(GridViewCommunityTopics); //.Controls.Add(GridViewCommunityTopics); } else GridViewCommunityTopics.DataSource = null; }
Last edited by peter_budo; Jul 11th, 2009 at 2:45 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Is this ASP.NET or GUI question? (Just so I can move this post to more relevant forum section. MS SQL section is more of queries questions and DB maintenance)
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
•
•
Join Date: Nov 2007
Posts: 5
Reputation:
Solved Threads: 0
hi friend ,
use following query in your code(sql command)
select case when date1 is null then 'date is not found' else convert(nvarchar,date1,105) end as date1 from datetest
regards,
rathnakar
use following query in your code(sql command)
select case when date1 is null then 'date is not found' else convert(nvarchar,date1,105) end as date1 from datetest
regards,
rathnakar
•
•
•
•
hi friends fetching datetime values from database, when data is null in code side it is displying the some garbage value instead that i want to show 'date is not found' the result is showind in grid view control
service written for fetching datetime
C# Syntax (Toggle Plain Text)
public List<Topics> GetAllTopicNames(int communityId) { List<Topics> communityTopiclist = new List<Topics>(); try { string connectionString = ConfigurationSettings.AppSettings["connectionString"]; SqlConnection con = new SqlConnection(connectionString); con.Open(); SqlCommand cmd = new SqlCommand("SELECT * from (select cd.Community_id,ct.Topic_id ,ct.Name,ct.Posts from Community_Details cd,Community_Topic_Details ct where ct.Community_Id = cd.Community_Id ) as C left join (select cr.topic_id , max(cr.reply_date) as RecentPost from Community_Topic_Details ctr,Community_Replys cr where ctr.topic_id=cr.topic_id group by cr.topic_id) as rep on rep .topic_Id=c.Topic_Id where C.Community_id=" + communityId.ToString(), con); SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows != false) { while (dr.Read()) { Topics communityTopics = new Topics(); if (dr["Topic_Id"] != System.DBNull.Value) communityTopics.TopicId = int.Parse(dr["Topic_Id"].ToString()); if (dr["Name"] != System.DBNull.Value) communityTopics.TopicName = dr["Name"].ToString(); if (dr["Posts"] != System.DBNull.Value) communityTopics.TopicPosts = int.Parse(dr["Posts"].ToString()); if (dr["RecentPost"] != System.DBNull.Value) communityTopics.LastPost = DateTime.Parse(dr["RecentPost"].ToString()); communityTopiclist.Add(communityTopics); } } else { return null; } } catch (Exception ex) { return null; } return communityTopiclist; } public void GetAllTopics() { CommunityManagement.CommunityManagementSoap topicService = new CommunityManagement.CommunityManagementSoapClient(); GetAllTopicNamesRequest topicRequest = new GetAllTopicNamesRequest(); topicRequest.Body = new GetAllTopicNamesRequestBody(); topicRequest.Body.communityId = int.Parse(Request.QueryString["communityId"]); GetAllTopicNamesResponse topicResponse = topicService.GetAllTopicNames(topicRequest); if (topicResponse != null && topicResponse.Body != null && topicResponse.Body.GetAllTopicNamesResult != null) { GridViewCommunityTopics.DataSource = topicResponse.Body.GetAllTopicNamesResult; GridViewCommunityTopics.DataBind(); PanelMiddle.Controls.Add(GridViewCommunityTopics); //.Controls.Add(GridViewCommunityTopics); } else GridViewCommunityTopics.DataSource = null; }
![]() |
Similar Threads
- Leaving out the YEAR in the datetime data type in sql (VB.NET)
- The conversion of a char data type to a datetime data type resulted in an out-of-rang (ASP.NET)
- Subtracting DateTime Data Type in SQL Server (ASP.NET)
- How to check data type (Visual Basic 4 / 5 / 6)
- DATETIME data type arithmenic in SQL Server 2005 (MS SQL)
- datetime/ i need only date (MS SQL)
- deleting a Binary search tree (C++)
- Exception Data is Null. This method or property cannot be called on Null values. (VB.NET)
- Getting the time from GetSystemTime (C)
Other Threads in the MS SQL Forum
- Previous Thread: Counting/Summation within dataset
- Next Thread: Update table row without firing trigger?
| Thread Tools | Search this Thread |






