我已經有了輸入工作,但現在我需要添加到原來的數字,每次我輸入數據庫,但我不知道該怎麼做,任何幫助如果您想更新現有記錄添加新的價值,你的領域,或插入新記錄,如果它不存在,你需要了解你的數據庫已經包含Username
將不勝感激:)不知道如何在數據庫中添加值
String myConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:/coursework/Databases/runner database.accdb;"; // location of the database
OleDbConnection myConnection = new OleDbConnection(myConnectionString); // To create the database connection
OleDbCommand myCommand = new OleDbCommand(); // Use the connection for the command
myCommand.Connection = myConnection;
try
{
myConnection.Open(); // Opens the database connection
string query = "insert into tblTrainingInformation ([Username],[Calories Burnt]) values('"+GlobalUsername.username+"','" + this.txtCaloriesBurntRun.Text + "')";
OleDbCommand createCommand = new OleDbCommand(query, myConnection);
createCommand.ExecuteNonQuery();
MessageBox.Show("Your running information has been saved");
myConnection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
什麼是失敗,消息是什麼。你也需要使用命令參數來避免sql注入。 – mybirthname
什麼是原始號碼? –
完美[Little Bobby Tables](http://imgs.xkcd.com/comics/exploits_of_a_mom.png)。 –