2015-05-21 57 views
-1

我有一個程序即時通訊正確處理股票和銷售。從Csharp窗口插入int到數據庫窗體

我加股票的形式需要說明電價和銷售電價,並添加到數據庫中,

我的問題是,將價格到數據庫中,當他們得到圓潤的小數點後錯過的數字。

我已經寫了到現在爲止這裏的代碼,

private void AddStockButton_Click(object sender, EventArgs e) 
    { 
     for (int i = 0; i < QtyNumber.Value;) 
     { 
      try 
      { 
       if (ItemDescription.Text == "") // check if textbox is empty 
       { 
        MessageBox.Show("You havent given the item a description"); // if the text box is empty show a message box 
        throw new Exception(); 
       } 

       if (ItemGroupList.SelectedIndex == -1) 
       { 
        MessageBox.Show("A Group must be selected"); 
        throw new Exception(); 
       } 

       if (PurchasePriceBox.Value == 0) 
       { 
        MessageBox.Show("Purchase Price cannot be 0"); 
        throw new Exception(); 
       } 

       if (SalePriceBox.Value == 0) 
       { 
        MessageBox.Show("Sale Price cannot be 0"); 
        throw new Exception(); 
       } 

       if (PurchasePriceBox.Value >= SalePriceBox.Value) 
       { 
        MessageBox.Show("Cannot sell for less that purchase price"); 
        throw new Exception(); 
       } 

       OleDbCommand com = new OleDbCommand("INSERT INTO Stocked_Items ([Item Description], [Purchase Price], [Purchase Date], [Group], [Sale Price]) VALUES (?, ?, ?, ?, ?)", Program.DB_CONNECTION); // add the information into the database 
       com.Parameters.Add(new OleDbParameter("", ItemDescription.Text)); 
       com.Parameters.Add(new OleDbParameter("", PurchasePriceBox.Value)); 
       com.Parameters.Add(new OleDbParameter("", DateTime.Today.Date)); 
       com.Parameters.Add(new OleDbParameter("", group[ItemGroupList.SelectedIndex].ID)); 
       com.Parameters.Add(new OleDbParameter("", SalePriceBox.Value)); 

       com.ExecuteNonQuery(); 
      } 
      catch 
      { 
      } 
      i++; 
     } 

誰能幫我插入全價包括小數點的數字(1.99例子currentley插入爲2和ID喜歡它去爲1.99 )

乾杯

+4

什麼是ms-access存儲價格的列的數據類型? – Sachu

+0

設置爲數字 – Ryanagray

+0

您是否嘗試過在OleDbParamater上設置'size'和'precision'? –

回答

0

我已經解決了這個問題,做了兩件事。

一,將數據庫中的數據類型從Number更改爲Decimal。

二,改變我如何將數字定義爲int到小數。

事情就像我現在想要的那樣工作。感謝您的評論。

相關問題