try
{
sqlCommandWithdraw.Connection.Open();
sqlCommandWithdraw.Parameters["@cardNumber"].Value = Class1.cardNumber;
readdata = sqlCommandWithdraw.ExecuteReader();
while (readdata.Read())
{
balanceDB = decimal.Parse(readdata["balance"].ToString());
}
decimal withdrawAmm = Convert.ToDecimal(textWithdraw.Text);
balanceDB = balanceDB - withdrawAmm;
sqlCommandWithdraw.Connection.Close();
sqlCommandUpdate.Connection.Open();
sqlCommandUpdate.Parameters["@cardNumber"].Value = Class1.cardNumber;
sqlCommandUpdate.Parameters["@balanceDB"].Value = Class1.cardNumber;
readdata = sqlCommandUpdate.ExecuteReader();
MessageBox.Show(balanceDB +" Successfully Withdrawn");
}
我工作的代碼自動取款機我有點東西在收回它看起來不錯,但似乎並沒有改變平衡,以反映在數據庫中的取款C#更新數據庫錯誤
我的命令是這樣的(更新)
update dbo.Accounts
set balance = @balanceDB
from dbo.ATMCards
INNER JOIN dbo.Accounts ON dbo.ATMCards.accountID = dbo.Accounts.accountID
where (dbo.ATMCards.cardNumber = @cardNumber)
,這是我的命令來選擇數據
select dbo.Accounts.balance
from dbo.ATMCards
INNER JOIN dbo.Accounts ON dbo.ATMCards.accountID = dbo.Accounts.accountID
where (dbo.ATMCards.cardNumber = @cardNumber)
似乎ŧ o運行得很好添加消息框檢查它感謝任何幫助感謝它!
而你的問題是什麼?除非我錯過它... – 2012-03-19 15:11:08
這看起來對我來說很可疑:sqlCommandUpdate.Parameters [「@ balanceDB」]。Value = Class1.cardNumber; – Liath 2012-03-19 15:12:31
該查詢是否可更新?爲什麼你說沒有工作(在數據庫中沒有看到它明顯的旁邊..) – gbianchi 2012-03-19 15:13:50