chris liatsos

chris liatsos

  • NA
  • 12
  • 519

executing stored procedure in c# bot application error

Nov 21 2018 4:17 AM
 
 
public async Task<DataTable> MessageReceivedNearestMuseums(string lat, string lng)
{
SqlConnection cnn = new SqlConnection("Data Source=CHRISTOS\\SQLEXPRESS;Initial Catalog=GuideDB;Integrated Security=True");
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataTable dt = new DataTable();
cnn.Open();
cmd = new SqlCommand("get_nearest_Restaurants", cnn);
cmd.Parameters.Add(new SqlParameter("@lat", lat));
cmd.Parameters.Add(new SqlParameter("@lng", lng));
cmd.CommandType = CommandType.StoredProcedure;
da.SelectCommand = cmd;
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
String mes = "Nearest Museum ID: " + dr[1].ToString() + "\nName:" + dr[2].ToString() + "\nCity: " + dr[3].ToString() + "\nLocation: " + dr[4].ToString();
await context.PostAsync(mes);
}
dr.Read();
cnn.Close();
context.Wait(MessageReceivedNearestMuseums);

Answers (4)