I want to create a json string inside "reader.Read()" how can I do that? This is for a API I'm creating so you can request the page for example api.ashx?tablename=CurrencySymbol&id=5 Hope someone can help
I would like to create json from column values from the database
** Lets not worry about the security of this, it's just for a internal application that only I will use **
public void ProcessRequest (HttpContext context)
{
context.Response.Clear();
string tablename = context.Request.QueryString["tablename"];
int ID = Int32.Parse(context.Request.QueryString["ID"]);
context.Response.ContentType = "text/html";
SqlConnection sqlConnection1 = new SqlConnection(ConfigurationManager.ConnectionStrings["WorldViewDatabase"].ConnectionString);
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;
cmd.CommandText = "SELECT * FROM " + tablename "WHERE ID = " + ID;
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlConnection1;
sqlConnection1.Open();
reader = cmd.ExecuteReader();
// Data is accessible through the DataReader object here.
while (reader.Read())
{
//context.Response.Write(reader);
}
sqlConnection1.Close();
context.Response.Write(ID);
context.Response.Write(tablename);
return;
}
usingstatements (not directives) in there)SQLinjections