嘿傢伙 我正在使用Visual Studio開發Windows窗體應用程序。 Csharp是正在使用的語言。我使用以下方法更新我的成員記錄。調用時它不會給我一個錯誤。但是當我檢查數據庫時,更新值不會發生。下面是下面的代碼:無法通過網絡上的SqlCeConnection更新數據庫3.5
public static void updatePersonInfo(int number, string password,string firstname, string lastname, string address, string city, string province, string postal, int typeid,bool suspend)
{
SqlCeConnection sqlConn = null;
SqlCeCommand cmdUpdate;
int susBit = 0;
if (suspend == true)
{
susBit = 1;
}
try
{
sqlConn = new SqlCeConnection(databaseString);
sqlConn.Open();
cmdUpdate = new SqlCeCommand(@"UPDATE PersonInfo
SET First_Name = @fname, Last_Name [email protected], Address = @address,
City = @city, Province = @prov, Postal_Code = @post, Type = @type,
Password = @pass, Suspended = @susp
WHERE Number = @numb", sqlConn);
cmdUpdate.Parameters.Add(new SqlCeParameter("@numb", SqlDbType.Int)).Value = number;
cmdUpdate.Parameters.Add(new SqlCeParameter("@fname", SqlDbType.NVarChar)).Value = firstname;
cmdUpdate.Parameters.Add(new SqlCeParameter("@lname", SqlDbType.NVarChar)).Value = lastname;
cmdUpdate.Parameters.Add(new SqlCeParameter("@address", SqlDbType.NVarChar)).Value = address;
cmdUpdate.Parameters.Add(new SqlCeParameter("@city", SqlDbType.NVarChar)).Value = city;
cmdUpdate.Parameters.Add(new SqlCeParameter("@prov", SqlDbType.NVarChar)).Value = province;
cmdUpdate.Parameters.Add(new SqlCeParameter("@post", SqlDbType.NVarChar)).Value = postal;
cmdUpdate.Parameters.Add(new SqlCeParameter("@type", SqlDbType.Int)).Value = typeid;
cmdUpdate.Parameters.Add(new SqlCeParameter("@pass", SqlDbType.NVarChar)).Value = password;
cmdUpdate.Parameters.Add(new SqlCeParameter("@susp", SqlDbType.Bit)).Value = susBit;
cmdUpdate.ExecuteNonQuery();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
finally
{
if (sqlConn != null)
{
sqlConn.Close();
}
}
}
正在調用該方法。我不明白爲什麼它不更新數據庫。它與刪除功能相同的問題。 – reggie 2010-12-12 11:26:45