我在windows phone 8應用程序中創建了本地數據庫。我有4個領域。wp8本地數據庫問題
userID - int
Username - string
FileName - string
FileByte - byte[]
我在做的是試圖更新FileByte列。但是,當我更新的專欄中,我得到異常SQL Server does not handle comparison of NText, Text, Xml, or Image data types.
這裏是我的DataTable
[Table]
public class UserFilesDetailsTable : INotifyPropertyChanged, INotifyPropertyChanging
{
// Define ID: private field, public property, and database column.
private int _userID;
[Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
public int userID
{
get { return _userID; }
set
{
if (_userID != value)
{
NotifyPropertyChanging("userID");
_userID = value;
NotifyPropertyChanged("userID");
}
}
}
// Define item name: private field, public property, and database column.
private string _Username;
[Column(DbType = "NVarChar(100) NOT NULL", CanBeNull = false)]
public string Username
{
get { return _Username; }
set
{
if (_Username != value)
{
NotifyPropertyChanging("Username");
_Username = value;
NotifyPropertyChanged("Username");
}
}
}
// Define item name: private field, public property, and database column.
private string _Filename;
[Column(DbType = "NVarChar(100) NOT NULL", CanBeNull = false)]
public string Filename
{
get { return _Filename; }
set
{
if (_Filename != value)
{
NotifyPropertyChanging("Filename");
_Filename = value;
NotifyPropertyChanged("Filename");
}
}
}
// Define item name: private field, public property, and database column.
private byte[] _Filebytes;
[Column(DbType = "image")]
public byte[] Filebytes
{
get { return _Filebytes; }
set
{
if (_Filebytes != value)
{
NotifyPropertyChanging("Filebytes");
_Filebytes = value;
NotifyPropertyChanged("Filebytes");
}
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
// Used to notify that a property changed
private void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
#region INotifyPropertyChanging Members
public event PropertyChangingEventHandler PropertyChanging;
// Used to notify that a property is about to change
private void NotifyPropertyChanging(string propertyName)
{
if (PropertyChanging != null)
{
PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
}
}
#endregion
}
這裏我更新查詢
public void addFiles(int userID, string userName, string fileName, byte[] fileBytes)
{
try
{
if (!(databaseTablesDB.usersFileDetailsTable.Where(f => f.Filename == fileName).Any()))
{
databaseTablesDB.usersFileDetailsTable.InsertOnSubmit(new UserFilesDetailsTable { userID = userID, Username = userName, Filename = fileName, Filebytes = fileBytes });
// Save changes to the database.
databaseTablesDB.SubmitChanges();
}
else
{
var fileDetails = (from file in databaseTablesDB.usersFileDetailsTable where file.Filename == fileName && file.Username == userName select file).FirstOrDefault();
if (fileDetails != null)
{
fileDetails.Filebytes = fileBytes;
}
databaseTablesDB.SubmitChanges();
}
}
catch (Exception ex)
{
}
}
我沒有得到哪裏是問題。有人可以幫助解決這個問題嗎?
爲什麼你有一個圖像的fileName和fileByte字段?只需保留fileName字段,並更新圖像即可將其覆蓋在隔離存儲中。 – Pantelis
@Pantelis感謝您的回覆。其實我想保存文件的字節數組。 –