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');
- 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;
-
- $tbl.empty();
-
- 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,UploadDate FROM tblActionDetaills WHERE IsRead=0 AND VID='" + 1 + "' Order By UploadDate DESC", connection))
- {
-
-
- 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.