I am getting the following error in my code.
Error converting data type nvarchar to float.
My code on button click is
protected void btnFind_Click(object sender, EventArgs e) { SqlParameter LatParam; SqlParameter LngParam; if (zipcode.Text != "") { litAddress.Text = ""; litAddress1.Text = ""; string addressstring = zipcode.Text; string connstring = "Data Source=win2008-2;Initial Catalog=h1tm11;User ID=sa;Password=#1cub3123*;Persist Security Info=True;"; string SQL1 = "SELECT *, 6371.01 * ACOS( SIN( @lat*PI()/180 ) * SIN( store_lat*PI()/180 ) + COS( @lat*PI()/180 ) * COS( store_lat*PI()/180 ) * COS( (store_long*PI()/180) - (@lng*PI()/180) ) ) AS distance from storelocator where 6371.01 * ACOS( SIN( @lat*PI()/180 ) * SIN( store_lat*PI()/180 ) + COS( @lng*PI()/180 ) * COS( store_lat*PI()/180 ) * COS( (store_long*PI()/180) - (@lng*PI()/180) ) ) < '" + ddl_distance.SelectedItem.Value + "' order by distance asc;"; SqlConnection conn = new SqlConnection(connstring); conn.Open(); SqlCommand comm = new SqlCommand(SQL1, conn); LatParam = new SqlParameter(); LatParam.ParameterName = "@lat"; LatParam.SqlDbType = SqlDbType.NVarChar; LatParam.Value = "select lat from tbl_pincode where codes='" + zipcode.Text + "';"; LngParam = new SqlParameter(); LngParam.ParameterName = "@lng"; LngParam.SqlDbType = SqlDbType.NVarChar; LngParam.Value ="select lat from tbl_pincode where codes='" + zipcode.Text + "';"; comm.Parameters.Add(LatParam); comm.Parameters.Add(LngParam); SqlDataReader reader = comm.ExecuteReader(CommandBehavior.CloseConnection); while (reader.Read()) { string area = reader["lat"].ToString(); string codes =reader["lng"].ToString(); litAddress.Text += area; litAddress1.Text += codes; } }
The datatype in the table are nvarchar for latitude,longitude and pincodes.
Thanks,