0
我使用以下方法將對象保存到SQL Server CE數據庫中。我現在停留在如何取回記錄。從SQL Server CE數據庫中檢索SqlDbType.Image類型的數據
public void SaveRecord(LabRecord _labrecord)
{
try
{
conn = new SqlCeConnection(_connectionString);
conn.Open();
MemoryStream memStream = new MemoryStream();
StreamWriter sw = new StreamWriter(memStream);
sw.Write(_labrecord);
SqlCeCommand sqlCmd = new SqlCeCommand("INSERT INTO LabTransactions([TrasactionType], [CAM], [TransactionObject]) VALUES ('ResultTest', 1234, @Image)", conn);
sqlCmd.Parameters.Add("@Image", SqlDbType.Image, Int32.MaxValue);
sqlCmd.Parameters["@Image"].Value = memStream.GetBuffer();
sqlCmd.ExecuteNonQuery();
}
finally
{
conn.Close();
}
}
更新
我期待再拍類返回一個特定的記錄。
public LabRecord getRecord(int transactionId)
{
LabRecord returnRecord = null;
try
{
conn = new SqlCeConnection(_connectionString);
conn.Open();
//.... Get the record
}
finally
{
conn.Close();
}
return returnRecord;
}
當你說「把記錄放回去」時,你的意思是從數據庫中刪除記錄(即刪除它),還是隻是獲取記錄的數據來顯示? – jaredk
我更新帖子並添加一些更多細節 –