This is my code in Asp.Net and C#. I am trying to figure out this error from 2 hours but unable to find.
Any kind of help is appreciated.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class Result : System.Web.UI.Page
{
SqlConnection con;
SqlCommand cmd;
SqlDataReader dr;
string city1, area1, type1, min, max;
int id;
protected void Page_Load(object sender, EventArgs e)
{
city1 = Request.QueryString["city"];
area1 = Request.QueryString["area"];
// type1 = Request.QueryString["propertytype"];
type1= "1bhk";
min = Request.QueryString["minprice"];
max = Request.QueryString["maxprice"];
// id = Convert.ToInt32(Request.QueryString["uid"]);
id = 1;
con = new SqlConnection("integrated security=true; database=data1; server=sudhir-pc");
con.Open();
cmd = new SqlCommand("select price,area,imagename,users_id from property where city='"+city1+"', area='"+area1+"', propertytype='"+type1+"', users_id="+id+"", con);
// cmd1 = new SqlCommand("select frstname,laststname,contactno from users where users_id='"+id+"'", con);
dr = cmd.ExecuteReader();
while (dr.Read())
{
Label1.Text = (string)dr["price"];
string area = (string)dr["area"];
string image = (string)dr["imagename"];
int id1 = (int)dr["users_id"];
}
}
}
Error line is dr=cmd.executereader();
. Same query runs on sql server. can this kind of error be logical?