I have two forms named Form1 and Form2:
Form1 is a list of some values that are inserted on a table in SQL Form2 is a validation of the values that are inserted on the table.
When I click the Form1 button, this will show up Form2 and Insert the values in the table, also Any inputs in textBox in Form 1 should be written back to Form2 TextBoxes.
I have the code below but it doesn't work.
////Form1 Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 F2= new Form2();
F2.Show();
this.Hide();
SqlConnection con = new SqlConnection("Data Source=MXPEDAMAP401;Initial Catalog=VentaCajas;User ID=sa;Password=1TservicesMX");
con.Open();
SqlCommand sc = new SqlCommand("insert into DatosGenerales values('" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','"+ textBox1.Text + "','" + listBox1.Text + "','" + textBox5.Text + "','" + listBox2.Text + "', getdate());",con);
int o=sc.ExecuteNonQuery();
MessageBox.Show("Verifica que los datos esten correctos");
con.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: esta línea de código carga datos en la tabla 'ventaCajasDataSet1.LugarEntrega' Puede moverla o quitarla según sea necesario.
this.lugarEntregaTableAdapter.Fill(this.ventaCajasDataSet1.LugarEntrega);
// TODO: esta línea de código carga datos en la tabla 'ventaCajasDataSet.TipoContrato' Puede moverla o quitarla según sea necesario.
this.tipoContratoTableAdapter.Fill(this.ventaCajasDataSet.TipoContrato);
}
}
}
////Form2 Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=MXPEDAMAP401;Initial Catalog=VentaCajas;User ID=sa;Password=1TservicesMX");
con.Open();
SqlCommand sc = new SqlCommand("delete DatosGenerales where No_Empleado+Tipo_Contrato = '';('" + textBox4.Text + "," + textBox5.Text + "');", con);
int o = sc.ExecuteNonQuery();
Form1 F1 = new Form1();
F1.Show();
this.Close();
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("¡Gracias!");
this.Close();
}
}
}
Some Screenshots [url=http://ift.tt/1b1XDGp]
How can I realize that?
Aucun commentaire:
Enregistrer un commentaire