Click here to Skip to main content
15,917,610 members

Comments by nicola_melc (Top 20 by date)

nicola_melc 1-Dec-14 10:40am View    
But, you used a DataGridView?
nicola_melc 1-Dec-14 10:21am View    
I've solved using a SqlDataReader.

This is my code:

string SQLquery = "SELECT * FROM dbo.ripRiparazioni";

SqlDataAdapter da = new SqlDataAdapter(SQLquery, connessione);

DataSet ds = new DataSet();

da.Fill(ds);

dgvListaRiparazioni.DataSource = ds.Tables[0];

SqlCommand command = new SqlCommand(SQLquery, connessione);

SqlDataReader reader = command.ExecuteReader();

foreach (DataGridViewRow righe in dgvListaRiparazioni.Rows)
{
if (reader.HasRows)
{
while (reader.Read())
{
DateTime date = (DateTime)righe.Cells["Data"].Value;
if (date.Date >= DateTime.Now.AddDays(-3).Date)
{
righe.DefaultCellStyle.BackColor = Color.White;
}
else
{
righe.DefaultCellStyle.BackColor = Color.Yellow;
}
}
}

}

Hope it is helpful.
nicola_melc 1-Dec-14 8:37am View    
If you put your code into try-catch you can show the error. Like this:

try
{

}
catch (Exception a)
{
MessageBox.Show(a.Message.ToString());
}

At the moment I have the same problem with my application.
Probabily when you did:

if (DC.getDataSet.Tables["StockDetails"].Rows.Count > 0)

It continually to count your rows also after the last.
nicola_melc 27-Nov-14 5:11am View    
Very good ! Thank You so much.
nicola_melc 27-Nov-14 4:20am View    
Another question:

if I want to read from database my data (@things) and split it, how can i do?

I'm using this code:

SqlCommand dati = new SqlCommand(selezioneDati, connessione);

SqlDataReader dr = dati.ExecuteReader();

DataTable dt = new DataTable("dbo.ripRiparazioni");

dt.Load(dr);

if (dt.Rows.Count > 0)
{
txtNome.Text = dt.Rows[0]["Nome"].ToString();
txtCognome.Text = dt.Rows[0]["Cognome"].ToString();
dtpData.Value = Convert.ToDateTime(dt.Rows[0]["Data"].ToString());
txtAnno.Text = dt.Rows[0]["Anno"].ToString();
txtCellulare.Text = dt.Rows[0]["Cellulare"].ToString();
txtIndirizzo.Text = dt.Rows[0]["Indirizzo"].ToString();
txtCitta.Text = dt.Rows[0]["Citta"].ToString();
txtMarca.Text = dt.Rows[0]["Marca"].ToString();
txtModello.Text = dt.Rows[0]["Modello"].ToString();
txtNumeroSerie.Text = dt.Rows[0]["NumeroSerie"].ToString();
rtbProblemaRiscontrato.Text = dt.Rows[0]["ProblemaRiscontrato"].ToString();

//read here @things and split. So I can put checked my checkbox directly from database
}
}