TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Bineeshcp Viswanath
NA
140
39.2k
How to get Convert Json datetime value in asp.net c#
Apr 17 2019 10:01 AM
Dear All,
I have a issue in connecting sql table value into signalr json query.
I am loading two value from table - descr(nvarchar) and uploadDate(DateTime).
I want to display date value in "dd/MM/yyyy format. Please help me on this.
The value from descr is loading perfectly by using below query:-
<script type=
"text/javascript"
>
function
getData() {
var
$tbl = $(
'#NotificationUL'
);
//tbl
var
$Count = $(
'#NotificationCount'
);
$.ajax({
url:
'wfrmUserPanel.aspx/GetData'
,
contentType:
"application/json; charset=utf-8"
,
dataType:
"json"
,
type:
"POST"
,
success:
function
(data) {
debugger
;
if
(data.d.length > 0) {
var
newdata = data.d;
// Count = data.rows.Count;
$tbl.empty();
//$tbl.append(' <tr><th>Description</th></tr>');
var
rows = [];
for
(
var
i = 0; i < newdata.length; i++) {
rows.push(
' <li><p>'
+ newdata[i].Description +
' <span class="timeline-icon"><i class="fa fa-comment-o" style="color: green"></i></span><span class="timeline-date">Date: '
+ newdata[i].UploadDate +
'</span> </p></li>'
);
}
$tbl.append(rows.join(
''
));
}
}
});
}
</script>
And the c# code I wrote to trigger this function is given below:-
[WebMethod]
public
static
IEnumerable<Products> GetData()
{
SqlDataReader reader =
null
;
try
{
using
(var connection =
new
SqlConnection(ConfigurationManager.ConnectionStrings[
"DataBase"
].ConnectionString))
{
connection.Open();
//using (SqlCommand command = new SqlCommand(@"SELECT [Description] FROM [dbo].[tblActionDetaills]", connection))
//{
using
(SqlCommand command =
new
SqlCommand(
"SELECT Description,UploadDate FROM tblActionDetaills WHERE IsRead=0 AND VID='"
+ 1 +
"' Order By UploadDate DESC"
, connection))
{
// Make sure the command object does not already have
// a notification object associated with it.
command.Notification =
null
;
SqlDependency.Start(ConfigurationManager.ConnectionStrings[
"DataBase"
].ConnectionString);
SqlDependency dependency =
new
SqlDependency(command);
dependency.OnChange +=
new
OnChangeEventHandler(dependency_OnChange);
if
(connection.State == ConnectionState.Closed)
connection.Open();
using
(reader = command.ExecuteReader())
return
reader.Cast<IDataRecord>()
.Select(x =>
new
Products()
{
Description = x.GetString(0),
UploadDate = x.GetDateTime(1)
}).ToList();
}
}
}
I have attached a file where you can see how the value displaying in the web page. Please find that file.
Attachment:
JsonNotification.rar
Reply
Answers (
5
)
oauth 2.0 token generation code using local sql db U&P
how to make a gridview that changes according to gridview ?