Israel

Israel

  • 698
  • 1.3k
  • 217.7k

Want to save date using time system not C# tool date

Apr 30 2014 11:33 AM
Hi!
 
All these codes work very well. I put all here to give you a good understanding to help me.
I have a table I can save safelly without problem. But I would like to learn how can I among these code to save my current time system directly in the column of my sql table (time of my computer). In other word, if its will mess to much in my code then which value can I for the date.
 
private void btnSave_Facturacao_Click(object sender, EventArgs e)
{
{
conn = new SqlConnection(connstr);
comm = new SqlCommand();
conn.Open();
SqlParameter S = new SqlParameter("@S", SqlDbType.NChar);
SqlParameter data = new SqlParameter("@dataFact", SqlDbType.Date);// here
SqlParameter nomecliente = new SqlParameter("@nc", SqlDbType.NChar);
SqlParameter designacao = new SqlParameter("@desig", SqlDbType.NChar);
SqlParameter codigo = new SqlParameter("@cod", SqlDbType.VarChar);
SqlParameter quantidade = new SqlParameter("@quant", SqlDbType.NChar);
SqlParameter precocompra = new SqlParameter("@precocompra", SqlDbType.NChar);
SqlParameter precosaida = new SqlParameter("@precosaida", SqlDbType.NChar);
SqlParameter total = new SqlParameter("@total", SqlDbType.NChar);
SqlParameter lucrovenda = new SqlParameter("@lucrovenda", SqlDbType.NChar);
SqlParameter troco = new SqlParameter("@troco", SqlDbType.NChar);
SqlParameter utilizador = new SqlParameter("@utilizador", SqlDbType.NChar);
comm.Parameters.Add(S);
comm.Parameters.Add(data);//here
comm.Parameters.Add(nomecliente);
comm.Parameters.Add(designacao);
comm.Parameters.Add(codigo);
comm.Parameters.Add(quantidade);
comm.Parameters.Add(precocompra);
comm.Parameters.Add(precosaida);
comm.Parameters.Add(total);
comm.Parameters.Add(lucrovenda);
comm.Parameters.Add(troco);
comm.Parameters.Add(utilizador);
S.Value = "*";
data.Value = dateTimePicker1.Value;//here
nomecliente.Value = nomeClienteFactu.Text;
designacao.Value = artigoFactu.Text;
codigo.Value = leituraCodFactu.Text;
quantidade.Value = quantidadeFactu.Text;
precocompra.Value = precocompraFactu.Text;
precosaida.Value = precosaidaFactu.Text;
total.Value = totalFactu.Text;
lucrovenda.Value = lucrovendaFactu.Text;
troco.Value = trocos.Text;
utilizador.Value = utilizadores.Text;
//total.Value = totalFactu.Text;
//lucrovenda.Value =
//troco
//utilizador
comm.Connection = conn;
comm.CommandText = "insert into fact values(@s,@datafact,@nc,@desig,@cod,@quant,@precocompra,@precosaida,@total,@lucrovenda,@troco,@utilizador)";
try
{
comm.ExecuteNonQuery();
MessageBox.Show("saved");
nomeClienteFactu.Clear();
/*artigoFactu.Text = "";
quantidadeFactu.Clear();
precoFactu.Clear();
totalFactu.Clear();*/
}
catch (Exception)
{
MessageBox.Show("Not saved");
}
finally
{
conn.Close();
}
}
}
private void Facturacao_Load(object sender, EventArgs e)
{
}
}
}
 

Answers (8)