i want to find and display image and it's related data on label and image control.
records are displaying on label but image not showing.
i have confussion how to implement below code..... can any one help to solve below code. its getting error....
Connection property has not been initialized.
my code is as below
protected void TxtLname_TextChanged(object sender, EventArgs e)
{
string firstName = txtFname.Text.Trim();
string MidName = txtMname.Text.Trim();
string LastName = TxtLname.Text.Trim();
string conString = ConfigurationManager.ConnectionStrings["myConn2"].ConnectionString;
string selectQuery = "SELECT * FROM " + "(" + " SELECT rpd.NAME,rpd.ADDRESS,rpd.CITYORVILLAGE,rpd.TALUKA, rpd.DISTRICT,rpd.CONTACTNO, rp.R_PHOTO, " + " REVERSE(PARSENAME(Replace(REVERSE(rpd.NAME), ' ', '.'), 1)) AS FirstName, " + " REVERSE(PARSENAME(Replace(REVERSE(rpd.NAME), ' ', '.'), 2)) AS MiddleName," + " REVERSE(PARSENAME(Replace(REVERSE(rpd.NAME), ' ', '.'), 3)) AS LastName " + " From RESTICTIED_PERSONS rpd" + " Join RESTICTED_PHOTO rp on rpd.ID = rp.RID)t " + "WHERE t.FirstName LIKE '%' + @First + '%'" + "AND t.MiddleName LIKE '%' + @Middle + '%'" + "AND t.LastName LIKE '%' + @Last + '%'";
using (SqlConnection con = new SqlConnection(this.con))
{
SqlCommand cmd = new SqlCommand(selectQuery);
cmd.Parameters.AddWithValue("@First", firstName);
cmd.Parameters.AddWithValue("@Middle", MidName);
cmd.Parameters.AddWithValue("@Last", LastName);
con.Open();
using (SqlDataReader dr = cmd.ExecuteReader())
{
if (dr.HasRows)
{
while (dr.Read() )
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
byte[] imgdata = (byte[])dr["R_PHOTO"];
string IMG = Convert.ToBase64String(imgdata, 0, imgdata.Length);
Blockperson.ImageUrl = "data:image/pnj;base64" + IMG;
Label1.Text = Convert.ToString(dt.Rows[0]["NAME"]);
Label2.Text = Convert.ToString(dt.Rows[0]["ADDRESS"]);
Label3.Text = Convert.ToString(dt.Rows[0]["CITYORVILLAGE"]);
Label4.Text = Convert.ToString(dt.Rows[0]["TALUKA"]);
Label5.Text = Convert.ToString(dt.Rows[0]["DISTRICT"]);
Label6.Text = Convert.ToString(dt.Rows[0]["CONTACTNO"]);
}
}
}
}
}
con.Close();
}
}