I'm trying to return the InvoiceID
from the database but it keeps returning -1
.
I'm trying to select the invoice ID From tblInvoice
to display it on a form and also use it to insert it into a second table that has a one to many relationship with tblInvoice
.
try
{
conn = new SqlConnection(conString);
conn.Open();
string select = "SELECT TOP 1 FId FROM tblFaktuur ORDER BY FId DESC";
SqlCommand cmd1 = new SqlCommand(select, conn);
i = (int)cmd1.ExecuteNonQuery();
}
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show("ReadInvoiceNumber()" + e.Message);
}
return i;
When Running the query SELECT TOP 1 FId FROM tblFaktuur ORDER BY FId DESC
in SQL Server it returns the value of 6
which is the last Invoice ID.