Israel

Israel

  • 631
  • 1.3k
  • 217.4k

Show me the last record after saving and on time....

Jul 10 2014 9:34 AM
Hi!
 
These codes allow me to save without problem.
But what I want to know it's after saving my record. I would like to see the latest record (only one culumn as I specify in my code) appear on my label just AFTER SAVING and ON TIME.
 
Please have a look:
 
private void btnGravar_Facturacao_Click(object sender, EventArgs e)
{
{
conn = new SqlConnection(connstr);
comm = new SqlCommand();
conn.Open();
SqlParameter numberprint = new SqlParameter("@numberprint", SqlDbType.NChar);
SqlParameter data = new SqlParameter("@datafact", SqlDbType.Date);
comm.Parameters.Add(numberprint);
comm.Parameters.Add(data);
numberprint.Value = lblNumberprint.Text;
data.Value = DateTime.Today;
comm.Connection = conn;
comm.CommandText = "insert into facturacao1 values(@numberprint,@datafact)";
 
 
//////////////////////////////////It's here where I try to write the code to show the latest record saving and every time on time//////////////////
string connectionString = @"Data Source=localhost\sqlexpress;Initial Catalog=master;Integrated Security=True";
SqlConnection sqlCon = new SqlConnection(connectionString);
sqlCon.Open();
string commandString = "select * from facturacao1 where numberprint ='" + lblNumberprint.Text + "'";
SqlCommand sqlCmd = new SqlCommand(commandString, sqlCon);
SqlDataReader read = sqlCmd.ExecuteReader();
if (read.HasRows)
{
while (read.Read())
{
lblNumberprint.Text = read["numberprint"].ToString();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
try
{
comm.ExecuteNonQuery();
MessageBox.Show("Saved");
}
catch (Exception)
{
MessageBox.Show("Not saved");
}
finally
{
conn.Close();
}
}
}
}
 

Answers (12)