I want to increase the number that the table in the database reached to -example:
My [CustomerNo]
reached 50, and I close the app, and open it again, I want it to complete from 50(++), and I want from the numbers to start again from 1 if they reached 250.
Globals.order++; is what i use .
Here is my code:
private void Order()
{
using (SqlConnection connection = new SqlConnection(connectionString1))
{
String query = "INSERT INTO Tbl_order (OrderName,Quantity,Price,Serves_way,Date,CustomerNo) VALUES (@OrderName,@Quantity, @Price,'" + servers + "','" + time1.ToString(format1) + "','" + Globals.order + "' )";
Globals.order++;
connection.Open();
using (SqlCommand command = new SqlCommand(query, connection))
{
// Add the length of this text column as third parameter...
command.Parameters.Add("OrderName", SqlDbType.NVarChar, 50);
command.Parameters.Add("Quantity", SqlDbType.Int);
command.Parameters.Add("Price", SqlDbType.Money);
command.Prepare();
for (int i = 0; i < lst_OrderName.Items.Count; i++)
{
command.Parameters[0].Value = lst_OrderName.GetItemText(lst_OrderName.Items[i]);
command.Parameters[1].Value = Convert.ToInt32(lst_QTY.Items[i]);
command.Parameters[2].Value = Convert.ToDouble(lst_Price2.Items[i]);
command.ExecuteNonQuery();
}
}
}
}
But when I close the app, it restart from 0 again.