我是一名初级程序员(高中生),我的老师给了我一项任务,sqlce
每次我在数据库中插入新行时,让表中的主键自动递增(我认为他不知道该怎么做它要么:)
这是我当前的代码:
using (SqlCeConnection con = new SqlCeConnection(conString))
{
con.Open();
using (SqlCeCommand com = new SqlCeCommand("INSERT INTO Occupational VALUES(@employedBeforeBool, @nameofEmployer, @Addressemployed,@specificsAtEmployer,@employmentOnDischarge, @yearsExperienceWithEmployer, @desireToReturnToEmployer, @farmingExperienceBool, @tradesorapprentiship, @whattradesorapprentiship, @SoldierID, @Occupational_ID)", con))
{
com.CommandText = "SET IDENTITY_INSERT Occupational ON";
com.Parameters.AddWithValue("@employedBeforeBool", Soldier1.employedBeforeBool);
com.Parameters.AddWithValue("@nameofEmployer", Soldier1.nameOfEmployer);
com.Parameters.AddWithValue("@Addressemployed", Soldier1.addressOfEmployer);
com.Parameters.AddWithValue("@specificsAtEmployer", Soldier1.specificsAtEmployer);
com.Parameters.AddWithValue("@employmentOnDischarge", Soldier1.employmentOnDischarge);
com.Parameters.AddWithValue("@yearsExperienceWithEmployer", Soldier1.yearsExperienceWithEmployer);
com.Parameters.AddWithValue("@desireToReturnToEmployer", Soldier1.desireToReturnToEmployer);
com.Parameters.AddWithValue("@farmingExperienceBool", Soldier1.farmingExperienceBool);
com.Parameters.AddWithValue("@tradesorapprentiship", Soldier1.tradeOrApprenticeship);
com.Parameters.AddWithValue("@whattradesorapprentiship", Soldier1.whattradesorapprentiship);
com.Parameters.AddWithValue("@SoldierID", SoldierID);
//com.Parameters.AddWithValue("@Occupational_ID", counter);
com.ExecuteNonQuery();
}
我的程序在运行时没有崩溃,看起来它正在插入,但表格内没有显示任何内容。