我正在使用Visual Studio 2010为我的代码开发一个使用C#的ASP.NET项目。我进行了一些搜索,但没有找到任何有助于解决这个问题的东西。当我单击更新按钮时,代码会处理但实际上不会更新记录。感谢我对此代码出错的任何指导。
protected void btnUpdate_Click(object sender, EventArgs e)
{
using (OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Coins.mdb;"))
{
using (OleDbCommand UpdateCoins = new OleDbCommand())
{
UpdateCoins.CommandType = CommandType.Text;
UpdateCoins.CommandText = "UPDATE [Coins] SET CoinName = ?, CurrencyType = ?, CoinType = ?, CoinValue = ?, YearIssued = ?, DateAcquired = ?, Email = ? WHERE ID = 12";
UpdateCoins.Parameters.AddWithValue("@CoinName", txtCoinName.Text);
UpdateCoins.Parameters.AddWithValue("@CurrencyType", txtCurrencyType.Text);
UpdateCoins.Parameters.AddWithValue("@CoinType", txtCoinType.Text);
UpdateCoins.Parameters.AddWithValue("@CoinValue", txtCoinValue.Text);
UpdateCoins.Parameters.AddWithValue("@YearIssued", txtYearIssued.Text);
UpdateCoins.Parameters.AddWithValue("@DateAcquired", txtDateAcquired.Text);
UpdateCoins.Parameters.AddWithValue("@Email", txtEmail.Text);
UpdateCoins.Connection = con;
con.Open();
UpdateCoins.ExecuteNonQuery();
con.Close();
}
}
Response.Redirect("DisplayCoin.aspx");
}
答案 0 :(得分:0)
我甚至没有想到影响我代码的page_load事件。我把它更改为以下内容,它没有问题。谢谢你的建议。
#include <ctime>
#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
/* Start: Do Not Change */
const int MAX = 5;
const int MIN = 1;
// This function takes tree ints as parameters
// and sets them to a random number
int spin(int & n1, int & n2, int & n3)
{
n1 = rand()%(MAX-MIN)+MIN;
n2 = rand()%(MAX-MIN)+MIN;
n3 = rand()%(MAX-MIN)+MIN;
}
/* End: Do Not Change */
int main()
{
int slot1, slot2, slot3;
double percent;
double credits = 1000.00;
char keepPlaying;
srand (time(NULL));
cout << "Welcome to the slots, you have 1,000.00 credits.\n"
<< "What percentage of credits do you want to bet(0-1)? ";
cin >> percent;
spin(slot1, slot2, slot3); // At this point slot1-3 all have a random value between 1 and 5
//spin function
cout << "Slot value = " << slot1 << "-" << slot2 << "-" << slot3 << endl;
while (slot1 != slot2 || slot1 != slot3 || slot2 != slot3)
{
if (slot1 == slot2 && slot1 == slot3 && slot2 == slot3)
{
cout << "\tYou won " << fixed << setprecision(2) << credits * percent << " credits!\n";
credits += (credits * percent);
cout << "Continue (y/n)? ";
cin >> keepPlaying;
if (keepPlaying == 'y')
{
cout << "You have " << credits << " credits left.\n";
cout << "What percentage of credits do you want to bet(0-1)? ";
cin >> percent;
spin(slot1, slot2, slot3);
cout << "Slot value = " << slot1 << "-" << slot2 << "-" << slot3 << endl;
continue;
}
else if (keepPlaying == 'n')
{
cout << "You are leaving with " << credits << " credits." << endl;
return 0;
}
}
else
{
cout << "\tSorry, you lost " << fixed << setprecision(2) << credits * percent << " credits." << endl;
credits -= (credits * percent);
cout << "Continue (y/n)? ";
cin >> keepPlaying;
if (keepPlaying == 'y' && credits != 0)
{
cout << "You have " << credits << " credits left.\n";
cout << "What percentage of credits do you want to bet(0-1)? ";
cin >> percent;
spin(slot1, slot2, slot3);
cout << "Slot value = " << slot1 << "-" << slot2 << "-" << slot3 << endl;
continue;
}
else if (keepPlaying == 'y' && credits == 0)
{
cout << "Get out of here bum!" << endl;
return 0;
}
else if (keepPlaying == 'n')
{
cout << "You are leaving with " << fixed << setprecision(2) << credits << " credits." << endl;
return 0;
}
}
}
return 0;
}`