private void BindGrid()//aqui solo actualiza las tablas para mostrar cualquier modificacion { //tomamos el valor de la coneccion a la base de datos definida anteriormente en el web.config using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlServer"].ToString())) { //declaramos el query using (SqlCommand cmd = new SqlCommand("Select I.id_uhi as 'ID', U.n_user as 'User', H.Name_HRI as 'HRI' from Users U inner join UHI I on I.id_user=U.id_user inner join HRI H on I.id_HRI=H.id_HRI ")) { //declaramos un adaptador sql using (SqlDataAdapter sda = new SqlDataAdapter()) { //hacemos la coneccion cmd.Connection = con; sda.SelectCommand = cmd; using (DataTable dt = new DataTable()) { sda.Fill(dt); //llenamos los valores TablaRel.DataSource = dt; // "" "" TablaRel.DataBind(); //"" "" } } } } //hacemos lo mismo que la parte anterior pero con otra tabla using (SqlConnection cons = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlServer"].ToString())) { using (SqlCommand cmd = new SqlCommand("Select id_user as 'ID', n_user as 'Usuario' from dbo.users ")) { using (SqlDataAdapter sda = new SqlDataAdapter()) { cmd.Connection = cons; sda.SelectCommand = cmd; using (DataTable dt = new DataTable()) { sda.Fill(dt); tablaus.DataSource = dt; tablaus.DataBind(); } } } } //lo mismo que anteriormente pero con otra tabla using (SqlConnection cons = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlServer"].ToString())) { using (SqlCommand cmd = new SqlCommand("Select id_HRI as 'ID', Name_HRI as 'HRI' from dbo.hri ")) { using (SqlDataAdapter sda = new SqlDataAdapter()) { cmd.Connection = cons; sda.SelectCommand = cmd; using (DataTable dt = new DataTable()) { sda.Fill(dt); gdvHRI.DataSource = dt; gdvHRI.DataBind(); } } } } }
protected void Button3_Click(object sender, EventArgs e) { using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlServer"].ToString())) { using (SqlCommand cmd = new SqlCommand("Select I.id_uhi as 'ID', U.n_user as 'User', H.Name_HRI as 'HRI' from Users U inner join UHI I on I.id_user=U.id_user inner join HRI H on I.id_HRI=H.id_HRI where U.n_user LIKE '%" + TextBox2.Text + "%'")) { using (SqlDataAdapter sda = new SqlDataAdapter()) { cmd.Connection = con; sda.SelectCommand = cmd; using (DataTable dt = new DataTable()) { sda.Fill(dt); TablaRel.DataSource = dt; TablaRel.DataBind(); } } } } }