public static int Agregar(ClassAgregarVideoJuego pClassAgregarVideoJuego) { int retorno = 0; using (SqlConnection Conn = conexiondb.obtnerConexion()) { SqlCommand Comando = new SqlCommand(string.Format("Insert Into VideoGameSQL (Nombre_VG, Consola_VG, Categoria_VG, Formato_VG) values('{0}','{1}','{2}','{3}')", pClassAgregarVideoJuego.NombreVideoJuego, pClassAgregarVideoJuego.TipoConsola, pClassAgregarVideoJuego.TipoCategoria, pClassAgregarVideoJuego.FormatoFiDi), Conn); retorno = Comando.ExecuteNonQuery(); } return(retorno); }
private void button_AgregarVG_Click(object sender, EventArgs e) { //List<ClassAgregarVideoJuego> ListVideoGame = new List<ClassAgregarVideoJuego>(); ClassAgregarVideoJuego VideoGame = new ClassAgregarVideoJuego(); VideoGame.NombreVideoJuego = textBox_Nombre.Text; VideoGame.TipoConsola = comboBox_Consola.Text; VideoGame.TipoCategoria = comboBox_Categoria.Text; VideoGame.FormatoFiDi = radioButton_Fisica.Text; //ListVideoGame.Add(VideoGame); int resultado = ClassAgregarVideoJuegosDAL.Agregar(VideoGame); //Validar RaddioButton if (radioButton_Fisica.Checked == true) { VideoGame.FormatoFiDi = "Física"; } else if (radioButton_Digital.Checked == true) { VideoGame.FormatoFiDi = "Digital"; } else { MessageBox.Show("Seleccione un formato para el Videojuego"); } if (radioButton_Fisica.Checked == true || radioButton_Digital.Checked == true) { MessageBox.Show("Agregado a la DataBase"); } SqlConnection Conn = new SqlConnection("Data Source=microservicessttk.database.windows.net;Initial Catalog=Northwind;Persist Security Info=True;User ID=adminSttk;Password=@Softtek01"); Conn.Open(); SqlCommand comando = new SqlCommand("Insert INTO Products values('" + textBox_Nombre.Text + "'," + comboBox_Consola.Text + ",'" + comboBox_Categoria.Text + "');"); int o = comando.ExecuteNonQuery(); MessageBox.Show(o + " : Record has been inserted"); Conn.Close(); //SqlCommand comando = new SqlCommand("Select * FROM Produc", Conn); //SqlDataAdapter adaptador = new SqlDataAdapter(); //adaptador.SelectCommand = comando; //DataTable tabla = new DataTable(); //adaptador.Fill(tabla); //Conn.Close(); }