public Boolean eliminar_tabla(Row_Persona nodoAux) { Boolean resultado = false; try { tabla.Clear(); string cs = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; //directo de web.config using (con = new SqlConnection(cs)) { con.Open(); using (SqlCommand command = new SqlCommand("DELETE FROM sentencias WHERE ID ='" + nodoAux.id + "' ", con)) { int responder = command.ExecuteNonQuery(); if (responder > 0) { resultado = true; } else { resultado = false; } } con.Close(); } } catch (SqlException e1) { System.Diagnostics.Debug.WriteLine("ERROR "); } return(resultado); }
protected void Button3_Click(object sender, EventArgs e) { Row_Persona nodoAux = new Row_Persona(); nodoAux.id = Convert.ToInt32(DropDownList2.SelectedItem.Value); datos.eliminar_tabla(nodoAux); GridView1.DataBind(); }
protected void Button2_Click(object sender, EventArgs e) { Row_Persona nodoAux = new Row_Persona(); nodoAux.apellido = txt_apellido.Text; nodoAux.nombre = txt_nombre.Text; nodoAux.dni = Convert.ToInt32(txt_dni.Text); nodoAux.fecha = String.Format("{0: yyyy-MM-dd}", txt_fecha.Text); //Convert.ToDateTime(String.Format("{0: yyyy-MM-dd}", txt_fecha.Text) ); // Convert.ToDateTime(String.Format("{0:d/M/yyyy HH:mm:ss}", txt_fecha.Text) ); nodoAux.id = Convert.ToInt32(DropDownList1.SelectedItem.Value); datos.update_tabla(nodoAux); GridView1.DataBind(); }
protected void Button1_Click1(object sender, EventArgs e) { Row_Persona nodoAux = new Row_Persona(); nodoAux.apellido = txt_apellido.Text; nodoAux.nombre = txt_nombre.Text; nodoAux.dni = Convert.ToInt32(txt_dni.Text); string dateAux2 = String.Format("{0: yyyy-MM-dd}", txt_fecha.Text); // DateTime dateAux3 = Convert.ToDateTime(String.Format("{0:yyyy-mm-dd }", txt_fecha.Text)); // nodoAux.fecha = DateTime.ParseExact(dateAux2, "yyyy-MM-dd", null); ; nodoAux.fecha = dateAux2; datos.insertar_tabla(nodoAux); GridView1.DataBind(); }
protected void actualizarTextBox() { if (RadioButtonList1.Items[0].Selected == true) { } else if (RadioButtonList1.Items[1].Selected == true) { Row_Persona row = (Row_Persona)datos.tabla[DropDownList1.SelectedIndex]; txt_apellido.Text = row.apellido; txt_nombre.Text = row.nombre; txt_dni.Text = row.dni.ToString(); txt_fecha.Text = row.fecha; } else if (RadioButtonList1.Items[2].Selected == true) { Row_Persona row = (Row_Persona)datos.tabla[DropDownList2.SelectedIndex]; txt_apellido.Text = row.apellido; txt_nombre.Text = row.nombre; txt_dni.Text = row.dni.ToString(); txt_fecha.Text = row.fecha; } }
public Boolean insertar_tabla(Row_Persona nodoAux) { Boolean resultado = false; try { tabla.Clear(); string cs = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; //directo de web.config using (con = new SqlConnection(cs)) { con.Open(); string textoCmd = "INSERT INTO Persona ( nomre , apellido , dni , date ) VALUES (' " + nodoAux.nombre + "' , '" + nodoAux.apellido + "' , '" + nodoAux.dni + "' , '" + nodoAux.fecha + " ' ) "; using (SqlCommand command = new SqlCommand(textoCmd, con)) { int responder = command.ExecuteNonQuery(); if (responder > 0) { resultado = true; } else { resultado = false; } } con.Close(); } } catch (SqlException e1) { System.Diagnostics.Debug.WriteLine("ERROR "); } return(resultado); }
public Boolean update_tabla(Row_Persona nodoAux) { Boolean resultado = false; try { tabla.Clear(); string cs = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; //directo de web.config using (con = new SqlConnection(cs)) { con.Open(); String strDate = nodoAux.fecha; string textoCmd = "UPDATE Persona SET nomre ='" + nodoAux.nombre + "' , apellido = '" + nodoAux.apellido + "' , dni = '" + nodoAux.dni + "' , date = '" + strDate + "' WHERE ID ='" + nodoAux.id + "' "; using (SqlCommand command = new SqlCommand(textoCmd, con)) { int responder = command.ExecuteNonQuery(); if (responder > 0) { resultado = true; } else { resultado = false; } } con.Close(); } } catch (SqlException e1) { System.Diagnostics.Debug.WriteLine("ERROR "); } return(resultado); }
public void actualizar_tabla() { try { tabla.Clear(); string cs = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; //directo de web.config using (con = new SqlConnection(cs)) { con.Open(); using (SqlCommand command = new SqlCommand("SELECT ID, nomre ,apellido ,dni, date FROM Persona", con)) using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { Row_Persona obj = new Row_Persona(); if (!reader.IsDBNull(0)) { obj.id = reader.GetInt32(0); if (!reader.IsDBNull(1)) { obj.nombre = reader.GetString(1); } else { obj.nombre = ""; } if (!reader.IsDBNull(2)) { obj.apellido = reader.GetString(2); } else { obj.apellido = ""; } if (!reader.IsDBNull(3)) { obj.dni = reader.GetInt32(3); } else { obj.dni = 0; } if (!reader.IsDBNull(4)) { obj.fecha = String.Format("{0: yyyy-MM-dd}", reader.GetDateTime(4));; } else { obj.fecha = ""; } tabla.Add(obj); } } } } } catch (SqlException e1) { System.Diagnostics.Debug.WriteLine("ERROR "); } }