private void UpdateGridViewJoke() { SqlConnection conn = new SqlConnection(dbconfig); SqlCommand cmd = null; SqlDataAdapter sda = null; DataTable dt = null; string sqlsel = "SELECT * FROM Joke"; try { cmd = new SqlCommand(sqlsel, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); GridViewJoke.DataSource = dt; GridViewJoke.DataBind(); } catch (Exception ex) { LabelMessageJoke.Text = ex.Message; } finally { conn.Close(); } }
public void UpdateGridViewJoke() { SqlConnection conn = new SqlConnection(dbconfig); SqlCommand cmd = null; SqlDataReader rdr = null; string sqlsel = "SELECT IdJoke as [Joke Id], Text, Type FROM Joke"; try { conn.Open(); cmd = new SqlCommand(sqlsel, conn); rdr = cmd.ExecuteReader(); GridViewJoke.DataSource = rdr; GridViewJoke.DataBind(); } catch (Exception ex) { LabelMessageJoke.Text = ex.Message; } finally { conn.Close(); } }