Click here to Skip to main content
16,011,839 members

Comments by denis.larocque (Top 6 by date)

denis.larocque 29-Apr-19 18:25pm View    
Thank you everyone all , work great now :)
denis.larocque 29-Apr-19 12:55pm View    
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
SqlConnection con;
public Form1()
{
InitializeComponent();
}

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_ProdMonitorTableAdapter.FillBy(this.isothermicDataSet.USR_ProdMonitor);
}

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{

bool selected = !Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells["check"].Value);
dataGridView1.Rows[1].Selected = true;
DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];

if (selected)
{

//change row color on Tab and change row
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];

//add date to Date_pec
SqlConnection con = new SqlConnection(@"Data Source=srvqcsql-01;Initial Catalog=Isothermic;Integrated Security=True");
SqlCommand cmd = new SqlCommand("update USR_ProdMonitor SET Date_PEC = GETDATE() where Poste = 'PARCLOSE' and Date_PEC is null and ScanDate = (select top 1 MIN(ScanDate) from USR_ProdMonitor where Poste = 'PARCLOSE' and Date_PEC is null)", con);

con.Open();
cmd.ExecuteNonQuery();
con.Close();

}
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);

}
this.uSR_ProdMonitorTableAdapter.FillBy(this.isothermicDataSet.USR_ProdMonitor);

}


}
}
denis.larocque 29-Apr-19 12:54pm View    
i have symplify and modify my code i now that work but..
when i want to refresh the datagrid nothing what i try work.

if i put datagrid1.refresh(); nothing refresh
and if i put this.uSR_ProdMonitorTableAdapter.FillBy(this.isothermicDataSet.USR_ProdMonitor);
that give me error:System.NullReferenceException  the object reference is not define an object instance.
denis.larocque 26-Apr-19 8:51am View    
ok i will start from zero, i have a BD on sql server and this db have already data on it.
on my program i have a datagrid to show this data. in this datagrid i have put a checkbox.
when i check this checkbox that will change the color of the row and go to next row. (this portion of code work great)

But i want in same time, add date and hour on cell in this selected row.(Date_pec) and in same time update the sql database and refresh the datagrid.
I dont no if im clear (my english is poor loll)
denis.larocque 26-Apr-19 8:39am View    
ok i have try that to, but that give me a error System.Data.SqlClient.SqlException : 'Incorrect syntax near '('.'

if (selected)
{
SqlConnection con = new SqlConnection(CONNECTION.CONNECTION_STRING_1);

SqlCommand cmd = new SqlCommand("UPDATE USR_ProdMonitor (Date_Pec) VALUES (@DATE)", con);
con.Open();
cmd.Parameters.AddWithValue("@DATE", DateTime.Now);
cmd.ExecuteNonQuery();
con.Close();