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 WindowsFormsApplication3 { public partial class Form1 : Form { SqlConnection con; SqlDataAdapter da; DataSet ds; SqlCommandBuilder builder; private int i; public Form1() { InitializeComponent(); con = new SqlConnection(CONNECTION.CONNECTION_STRING_1); } private void Form1_Load(object sender, EventArgs e) { // TODO: cette ligne de code charge les données dans la table 'isothermicDataSet.USR_ProdMonitor'. Vous pouvez la déplacer ou la supprimer selon les besoins. this.uSR_ProdMonitorTableAdapter2.Fill(this.isothermicDataSet.USR_ProdMonitor); string sql = "SELECT date_pec,scandate,Poste,NoSeq,Couleur,ProductionLot FROM USR_ProdMonitor WHERE (Poste = N'Parclose')"; ds=new DataSet(); da=new SqlDataAdapter(sql,con); da.Fill(ds); builder=new SqlCommandBuilder(da); dataGridView1.DataSource=ds.Tables[0]; } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { bool selected = !Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells["check"].Value); dataGridView1.Rows[1].Selected = true; if (selected) { SqlConnection con = new SqlConnection(CONNECTION.CONNECTION_STRING_1); string SqlCmdText = "INSERT INTO USR_ProdMonitor(Date_Pec)" + DateTime.Now (); int next = this.dataGridView1.CurrentRow.Index + 1; dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red; this.dataGridView1.CurrentCell = this.dataGridView1.Rows[next].Cells[this.dataGridView1.CurrentCell.ColumnIndex]; } else { dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.LightGreen; dataGridView1.Rows[e.RowIndex].Cells["check"].Value = !Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells["check"].Value); } { } } private void button1_Click(object sender, EventArgs e) { Application.Exit(); } } }
using (SqlConnection con = new SqlConnection(CONNECTION.CONNECTION_STRING_1)) using (SqlCommand cmd = new SqlCommand("INSERT INTO USR_ProdMonitor (Date_Pec) VALUES (@Date_Pec)", con)) { cmd.Parameters.AddWithValue("@Date_Pec", DateTime.Now); con.Open(); cmd.ExecuteNonQuery(); }
INSERT
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)