I've retrieved data from database, and I've stored it in a 2D array (jagged).
SqlConnection con = new SqlConnection("Data Source=COMP7;Initial Catalog=GK_Practice;User ID=sa;Password=SQLEXPRESS");
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from employee";
con.Open();
SqlDataReader rd = cmd.ExecuteReader();
int rowcount=0, columncount;
while(rd.Read())
{
rowcount++;
}
columncount = rd.FieldCount;
rd.Close();
rd = cmd.ExecuteReader();
string[][] str=new string[rowcount][];
int i = 0;
while(rd.Read())
{
str[i] = new string[columncount];
for (int j = 0; j < columncount; j++)
{
str[i][j] = rd.GetValue(j).ToString();
}
i++;
}
Label2.Text = str[1][1].ToString();
JavaScriptSerializer js = new JavaScriptSerializer();
string json = js.Serialize((object)str);
Response.Write(json);
rd.Close();
con.Close();
Now I've serialized this so as to pass as JSON, to be used at the client (browser). When I say Response.Write(json); it gives the following output:
[["1","John","xyz","12000"],["2","Mike","pqr","15000"],["3","Nick","fjdu","18000"],["4","Brad","wee","22000"]]
But I want this data to be stored in JavaScript variable (say \var x) and use it as x[0][1].
Is that even possible?