Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data;
- using System.Data.SqlClient;
- using System.Configuration;
- public partial class _Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (Request.QueryString["callback"] != null)
- {
- SqlConnection con = new SqlConnection();
- con.ConnectionString = ConfigurationManager.ConnectionStrings["cn"].ConnectionString;
- if (con.State == ConnectionState.Closed)
- {
- con.Open();
- }
- String outputText = Request.QueryString["callback"].ToString() + "(" + "{";
- SqlCommand cmd = new SqlCommand("select id,name from profiles", con);
- SqlDataReader dr = cmd.ExecuteReader();
- var yourlist1 = new List<String>();
- var yourlist2 = new List<String>();
- if (dr.HasRows)
- {
- while (dr.Read())
- {
- yourlist1.Add('"' + dr[0].ToString() + '"' + ":" + '"' + dr[1].ToString() + '"');
- }
- }
- Array k = yourlist1.ToArray();
- outputText += Convert.ToString(k.GetValue(0));
- for (Int32 i = 1; i < k.Length; i++)
- {
- outputText += "," + Convert.ToString(k.GetValue(i));
- }
- outputText += "}" +");";
- Response.Write(outputText);
- dr.Close();
- cmd.Dispose();
- con.Close();
- }
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- SqlConnection con = new SqlConnection();
- con.ConnectionString = ConfigurationManager.ConnectionStrings["cn"].ConnectionString;
- if (con.State == ConnectionState.Closed)
- {
- con.Open();
- }
- SqlCommand cmd = new SqlCommand("select id,name from profiles", con);
- SqlDataReader dr = cmd.ExecuteReader();
- var yourlist1 = new List<String>();
- var yourlist2 = new List<String>();
- if (dr.HasRows)
- {
- while (dr.Read())
- {
- yourlist1.Add('"' + dr[0].ToString() + '"' + ":" + '"' + dr[1].ToString() + '"');
- }
- }
- Array k = yourlist1.ToArray();
- //classic logic
- Response.Write("(" + "{");
- //
- for (Int32 i = 0; i < k.Length; i++)
- {
- Response.Write(Convert.ToString(k.GetValue(i)) + ",");
- }
- //
- Response.Write("}" + ")");
- dr.Close();
- cmd.Dispose();
- con.Close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment