1

I have a SQL Server database I would like to parse using jQuery.

My intent is that in jQuery, I can look for ID="orange", and it will return all the values in that row.

Can you recommend a good tutorial on how to do this?

I am using an ASP.NET web page with C# codebehind, SQL Server, and jQuery.

EDIT: Ok so after I have serialized the datatable, how do I end up using that in jQuery? Both the linked question and the link the answer referenced don't seem to go into that.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
anesthetic
  • 193
  • 2
  • 18
  • 3
    Possible duplicate of [how to convert datatable to json in C#](http://stackoverflow.com/questions/17398019/how-to-convert-datatable-to-json-in-c-sharp) – Sean Wessell Dec 14 '16 at 20:34
  • Please show what you have tried... – DevlshOne Dec 14 '16 at 20:34
  • I was originally creating an HTML table to parse with jquery. And I was told to create a javascript object instead. So now I'm trying to figure out how to even begin. A lot of what I've seen uses PHP and I'm trying to avoid that. – anesthetic Dec 14 '16 at 20:38
  • try searching for JSON and you will find your answer faster – Parv Sharma Dec 14 '16 at 20:52
  • @anesthetic - Check the 1st comment from Sean. I've also flagged it as a possible duplicate. – t1f Dec 14 '16 at 20:53
  • Sorry I guess I'm just missing how to go from serializing the datatable to searching it in jquery. In the first solution of that other example, can you just reference "rows" in jquery? – anesthetic Dec 14 '16 at 20:58

1 Answers1

0

if you have to access data table data using jquery then first you create a method to access data using c#

  1. create a method which return data in datatable and then using NewtonSoft.JSON dll you will convert datatable into json data i.e. in string form and then return this string.

  2. in client side that is in jquery you convert the data into json format using jquery.parseJSON method and access the data using jquery

use below code :
IN C# write method and convert datatable data into json string:

using NewtonSoft.JSON;

string jsonstring=string.empty;
jsonstring=JSONConvert.Serializeobject(dt);    //dt is nothing but your datatable object
return jsonstring;

in client side that is in jquery side write below code to convert jsonstring into object and access data

var obj=Jquery.parseJSON(jsonstring);    //obj=jquery.parseJSON(data)
var sam=obj.Name   //name is nothing but your  property name you cann access the value using obj object
סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
RiyajKhan
  • 55
  • 4