public int InsertOrder(Order order) { string sql = "Insert into tbl_orders(StockID,RequestID,OrderDt,OrderSide,Quantity,AvlQuantity,Price) values(@stock,@request,@orddt,@ordSide,@quantity,@avlquantity,@price) ; SELECT last_insert_rowid();"; try { using (IDbConnection conn = _OrderDatabase.CreateConnection(_ConnString)) { using (IDbCommand command = _OrderDatabase.CreateCommand(sql, conn)) { command.Parameters.Add(_OrderDatabase.PrepareParameter("@stock", order.StockId)); command.Parameters.Add(_OrderDatabase.PrepareParameter("@request", order.RequestId)); command.Parameters.Add(_OrderDatabase.PrepareParameter("@orddt", order.SubmittedDt)); command.Parameters.Add(_OrderDatabase.PrepareParameter("@ordSide", (int)order.OrderSide)); command.Parameters.Add(_OrderDatabase.PrepareParameter("@quantity", order.Quantity)); command.Parameters.Add(_OrderDatabase.PrepareParameter("@avlquantity", order.Quantity)); command.Parameters.Add(_OrderDatabase.PrepareParameter("@price", order.Price)); object obj = command.ExecuteScalar(); int id = Convert.ToInt32(obj); return(id); } } } catch (Exception ex) { Console.WriteLine(ex.Message); return(0); } }
public IList <Stock> FetchStocks() { if (Stocklist == null) { Stocklist = new List <Stock>(); string sql = "Select ID,StockID from tbl_StockNames;"; try { using (IDbConnection conn = _OrderDatabase.CreateConnection(_ConnString)) { using (IDbCommand command = _OrderDatabase.CreateCommand(sql, conn)) { IDataReader r = command.ExecuteReader(); while (r.Read()) { Stocklist.Add(new Stock { StockID = Convert.ToInt32(r["ID"]), StockName = Convert.ToString(r["StockId"]) }); } return(Stocklist); } } } catch (Exception ex) { return(Stocklist); } } else { return(Stocklist); } }