Results 1 to 5 of 5

Thread: Howto or Intro to JSON(Reader) and Arrayreader

  1. #1
    Premium Member
    Join Date
    Mar 2012
    Posts
    146

    Howto or Intro to JSON(Reader) and Arrayreader

    Hello

    I am fairly new to Javascript / Ext.Net and I am struggling a bit with data from databases and their connections. In my case at the moment especially with combo boxes and how to fill them in an efficient way. Does anyone know a good source or article to get me into the right direction? I was searching the Net for a while but haven't come up with something that gave me a head start.

    Until now I have done everything with VS 2010, C# and the ASP.NET AJAX Control Toolkit and it was straight forward. Since I started using Ext.net I don't want to go back :)

    Thank you very much for your inputs, any help is very much appreciated.

    best regards!

  2. #2
    Member plykkegaard's Avatar
    Join Date
    Feb 2009
    Location
    Denmark
    Posts
    343
    I have used the forums on sencha.com and stackoverflow.com in my quest

    There's a few oddities enabling the ASP.NET to use scriptservices but actually .NET 4 supports Json almost out of the box and it's quite easy when you have taken the dive

    What kind of obstacles are you facing?

    rgds/Peter

  3. #3
    Premium Member
    Join Date
    Mar 2012
    Posts
    146
    Hello Peter

    Thanks for you answer. I managed to get some data out now but I could still need some advice from someone who knows the stuff better than I do.

    For the JSONReader I am just taking a DataTable now and using the JSON.Serialize from Ext.net in an .ashx-file which I load dynamically:
    Code:
    public void ProcessRequest (HttpContext context) {
            
            string connectionString = WebConfigurationManager.ConnectionStrings["ConnectionString_KDM6"].ConnectionString;
            SqlConnection myConnection = new SqlConnection(connectionString);
            string qry = "";
    
            DataTable dt = new DataTable();
            if (!string.IsNullOrEmpty(context.Request["query"]))
            {
                qry = "SELECT ID_COMPANY, COMPANY FROM tbl_company WHERE COMPANY LIKE '%" + context.Request["query"] + "%'";
            }
            else
            {
                qry = "SELECT ID_COMPANY, COMPANY FROM tbl_company";
            }
            
            SqlCommand myCommand = new SqlCommand(qry, myConnection);
            SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);
    
            // try to get data with sql query
            try
            {
                myAdapter.Fill(dt);
            }
            finally
            {
            }
            
            context.Response.ContentType = "text/json";
            context.Response.Write(string.Format("{{'companies':{0}}}", JSON.Serialize(dt)));
        }
    This seems to be pretty straight forward and I am not sure if it could be done in an easier way. If so, don't hesitate to tell me.

    For the ArrayReader on the other hand I am using something like this in a normal C# file which I load in the beginning into the store (from an example in the forum):
    Code:
    public static Object GetDropdownList(string tableName, string column)
        {
            Object[] tmpObject = null;
            DataTable tmpTable = new DataTable();
            String tmpSQLQuery = "SELECT * FROM [" + tableName + "] ORDER BY [" + column + "] ASC";
            SqlCommand myCommand = new SqlCommand(tmpSQLQuery, myConnection);
            SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);
    
    
            // try to get data with sql query
            try
            {
                myAdapter.Fill(tmpTable);
            }
            finally
            {
            }
    
            // convert data table to object array
            if (tmpTable.Rows.Count > 0)
            {
                tmpObject = new object[tmpTable.Rows.Count];
                for (int i = 0; i < tmpTable.Rows.Count; i++)
                {
                    tmpObject[i] = new object[] { tmpTable.Rows[i]["ID_" + column].ToString(), tmpTable.Rows[i][column].ToString() };
                }
            }
    
            // dispose unused stuff
            myCommand.Dispose();
            myAdapter.Dispose();
            tmpTable.Dispose();
            tmpSQLQuery = null;
    
            return tmpObject;
        }
    Here I am pretty sure that this object stuff is a huge overhead but I have no clue what I could do better?!

    You wrote something about JSON and .NET 4 is straight forward. Could you please elaborate?

    Thank you very much for you input.

    best regards!

  4. #4
    Member plykkegaard's Avatar
    Join Date
    Feb 2009
    Location
    Denmark
    Posts
    343
    Check this MSDN article as a start
    http://msdn.microsoft.com/en-us/libr...attribute.aspx

    And why you don't have to serialize manually
    http://encosia.com/asp-net-web-servi...serialization/

    Please note you need to use a object which can be serialized for the above to work

    - Peter

  5. #5
    Premium Member
    Join Date
    Mar 2012
    Posts
    146
    Cool, thanks. I will read through those pages, they seem exactly what I wanted and come back to this thread. It won't be before Mai though because I am just starting a longer vacation ;)

    cheers.

Similar Threads

  1. [CLOSED] ArrayReader: databind
    By RomualdAwessou in forum 1.x Premium Help
    Replies: 2
    Last Post: Aug 03, 2010, 7:36 PM
  2. [CLOSED] Advanced XML / JSON Reader
    By Immobilmente in forum 1.x Premium Help
    Replies: 5
    Last Post: Feb 09, 2010, 5:53 AM
  3. Json reader not retrive all pages of data in grid panel
    By Satyanarayana murthy in forum 1.x Help
    Replies: 0
    Last Post: Dec 05, 2009, 4:58 AM
  4. [CLOSED] Passing JSON to Reader
    By Ben in forum 1.x Premium Help
    Replies: 5
    Last Post: Dec 02, 2008, 1:38 PM
  5. Replies: 4
    Last Post: Nov 25, 2008, 5:53 PM

Posting Permissions