Here is an example of code that selects every record in a table. Could someone perhaps demonstrate how to choose the last record in that table?
select * from table
The following command: SELECT * FROM TABLE ORDER BY ID DESC LIMIT I experience the following error: Incorrect syntax close to "LIMIT" in line 1. I use the following code:
private void LastRecord()
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["HELPDESK_OUTLOOKConnectionString3"].ToString());
conn.Open();
SqlDataReader myReader = null;
SqlCommand myCommand = new SqlCommand("SELECT * FROM HD_AANVRAGEN ORDER BY " +
"aanvraag_id DESC LIMIT 1", conn);
myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
TextBox1.Text = (myReader["aanvraag_id"].ToString());
TextBox1.Text += (myReader["wijziging_nummer"].ToString());
TextBox1.Text += (myReader["melding_id"].ToString());
TextBox1.Text += (myReader["aanvraag_titel"].ToString());
TextBox1.Text += (myReader["aanvraag_omschrijving"].ToString());
TextBox1.Text += (myReader["doorlooptijd_id"].ToString());
TextBox1.Text += (myReader["rapporteren"].ToString());
TextBox1.Text += (myReader["werknemer_id"].ToString());
TextBox1.Text += (myReader["outlook_id"].ToString());
}
}
Can someone please help me with this?