當前位置:首頁 » 操作系統 » 資料庫保存對象

資料庫保存對象

發布時間: 2022-05-13 21:20:21

⑴ 如何:將數據從對象保存到資料庫

有關更多信息,請參見 TableAdapter 概述。若要保存對象集合中的數據,請循環通過對象集合(例如,for-next 循環),然後使用 TableAdapter 的 DBDirect 方法之一將每個對象的值發送到資料庫中。默認情況下,DBDirect 方法在 TableAdapter 上創建,能夠直接對資料庫執行操作。這些方法可以直接調用,它們不要求 DataSet 或DataTable 對象來協調更改即可將更新發送到資料庫。注意配置TableAdapter 時,主查詢必須提供足夠的信息,才能創建 DBDirect 方法。例如,如果將 TableAdapter 配置為從未定義主鍵列的表中查詢數據,它將不會生成 DBDirect 方法。 TableAdapter DBDirect 方法 說明TableAdapter.Insert向資料庫中添加新記錄,此方法允許將值作為方法參數傳入各個列。TableAdapter.Update更新資料庫中的現有記錄。Update 方法將原始列值和新列值用作方法參數。原始值用於定位原始記錄,新值用於更新該記錄。通過將 DataSet、DataTable、DataRow、或 DataRow 數組用作方法參數,TableAdapter.Update 方法還可用於將數據集中的更改協調回資料庫。TableAdapter.Delete在基於作為方法參數傳入的原始列值的資料庫中,刪除其現有記錄。將對象中的新記錄保存到資料庫中通過將值傳遞給 TableAdapter.Insert 方法可創建這些記錄。下面的示例通過將 currentCustomer 對象中的值傳遞給 TableAdapter.Insert 方法,在 Customers 表中創建一項新的客戶記錄。 Visual Basic PrivateSub AddNewCustomer(ByVal currentCustomer As Customer) CustomersTableAdapter.Insert( _ currentCustomer.CustomerID, _ currentCustomer.CompanyName, _ currentCustomer.ContactName, _ currentCustomer.ContactTitle, _ currentCustomer.Address, _ currentCustomer.City, _ currentCustomer.Region, _ currentCustomer.PostalCode, _ currentCustomer.Country, _ currentCustomer.Phone, _ currentCustomer.Fax) EndSub C# privatevoid AddNewCustomers(Customer currentCustomer) { customersTableAdapter.Insert( currentCustomer.CustomerID, currentCustomer.CompanyName, currentCustomer.ContactName, currentCustomer.ContactTitle, currentCustomer.Address, currentCustomer.City, currentCustomer.Region, currentCustomer.PostalCode, currentCustomer.Country, currentCustomer.Phone, currentCustomer.Fax); } J# privatevoid AddNewCustomers(Customer currentCustomer) { .Insert( currentCustomer.get_CustomerID(), currentCustomer.get_CompanyName(), currentCustomer.get_ContactName(), currentCustomer.get_ContactTitle(), currentCustomer.get_Address(), currentCustomer.get_City(), currentCustomer.get_Region(), currentCustomer.get_PostalCode(), currentCustomer.get_Country(), currentCustomer.get_Phone(), currentCustomer.get_Fax()); }將對象中的現有記錄更新到資料庫修改記錄:調用 TableAdapter.Update 方法並傳入新值可更新記錄,而傳入原始值可定位記錄。注意對象需要保留其原始值,才能將它們傳遞給 Update 方法。此示例使用前綴為 orig 的屬性存儲原始值。下面的示例通過將 Customer 對象中的新值和原始值傳遞給 TableAdapter.Update 方法,更新 Customers 表中的現有記錄。 Visual Basic PrivateSub UpdateCustomer(ByVal cust As Customer) CustomersTableAdapter.Update( _ cust.CustomerID, _ cust.CompanyName, _ cust.ContactName, _ cust.ContactTitle, _ cust.Address, _ cust.City, _ cust.Region, _ cust.PostalCode, _ cust.Country, _ cust.Phone, _ cust.Fax, _ cust.origCustomerID, _ cust.origCompanyName, _ cust.origContactName, _ cust.origContactTitle, _ cust.origAddress, _ cust.origCity, _ cust.origRegion, _ cust.origPostalCode, _ cust.origCountry, _ cust.origPhone, _ cust.origFax) EndSub C# privatevoid UpdateCustomer(Customer cust) { customersTableAdapter.Update( cust.CustomerID, cust.CompanyName, cust.ContactName, cust.ContactTitle, cust.Address, cust.City, cust.Region, cust.PostalCode, cust.Country, cust.Phone, cust.Fax, cust.origCustomerID, cust.origCompanyName, cust.origContactName, cust.origContactTitle, cust.origAddress, cust.origCity, cust.origRegion, cust.origPostalCode, cust.origCountry, cust.origPhone, cust.origFax); } J# privatevoid UpdateCustomer(Customer cust) { .Update( cust.get_CustomerID(), cust.get_CompanyName(), cust.get_ContactName(), cust.get_ContactTitle(), cust.get_Address(), cust.get_City(), cust.get_Region(), cust.get_PostalCode(), cust.get_Country(), cust.get_Phone(), cust.get_Fax(), cust.get_origCustomerID(), cust.get_origCompanyName(), cust.get_origContactName(), cust.get_origContactTitle(), cust.get_origAddress(), cust.get_origCity(), cust.get_origRegion(), cust.get_origPostalCode(), cust.get_origCountry(), cust.get_origPhone(), cust.get_origFax()); }刪除資料庫中的現有記錄通過調用 TableAdapter.Delete 方法並傳入原始值定位記錄,可刪除記錄。注意對象需要保留其原始值,才能將它們傳遞給 Delete 方法。 Visual Basic PrivateSub DeleteCustomer(ByVal cust As Customer) CustomersTableAdapter.Delete( _ cust.origCustomerID, _ cust.origCompanyName, _ cust.origContactName, _ cust.origContactTitle, _ cust.origAddress, _ cust.origCity, _ cust.origRegion, _ cust.origPostalCode, _ cust.origCountry, _ cust.origPhone, _ cust.origFax) EndSub C# privatevoid DeleteCustomer(Customer cust) { customersTableAdapter.Delete( cust.origCustomerID, cust.origCompanyName, cust.origContactName, cust.origContactTitle, cust.origAddress, cust.origCity, cust.origRegion, cust.origPostalCode, cust.origCountry, cust.origPhone, cust.origFax); } J# privatevoid DeleteCustomer(Customer cust) { .Delete( cust.get_origCustomerID(), cust.get_origCompanyName(), cust.get_origContactName(), cust.get_origContactTitle(), cust.get_origAddress(), cust.get_origCity(), cust.get_origRegion(), cust.get_origPostalCode(), cust.get_origCountry(), cust.get_origPhone(), cust.get_origFax()); }安全您必須具有相應的許可權,才能對資料庫中的表執行選定的 INSERT、UPDATE 或 DELETE。

⑵ SQL Server中,保存著每個資料庫對象的信息的系統表是

保存著每個資料庫對象的信息的系統表是 Sysobjects

⑶ C#如何把一個類的對象存入資料庫(此時在資料庫裡面應該保存成什麼數據類型)

可以使用.net提供的序列化和反序列化方法來實現,你可將對象序列化成XML字元串,然後存入資料庫中,當你要使用對象的時候,再把資料庫中保存字元串反序列化成對象就可以使用了,以下為示例代碼:

publicclassCat
{
publicstringColor{get;set;}
publicintSpeed{get;set;}
publicstringName{get;set;}
}
//序列化
varcat1=newCat{Color="Write",Speed=50,Name="MiMi"};
XmlSerializerser=newXmlSerializer(typeof(Cat));
MemoryStreamms=newMemoryStream();
ser.Serialize(ms,cat1);
stringxmlString=Encoding.UTF8.GetString(ms.ToArray());
//xmlString就是你要保存到資料庫的字元串

//反序列化
XmlSerializerdser=newXmlSerializer(typeof(Cat));
//xmlString是你從資料庫獲取的字元串
StreamxmlStream=newMemoryStream(Encoding.UTF8.GetBytes(xmlString));
Catcat2=dser.Deserialize(xmlStream)asCat;//cat2就是你要得到的class對象

⑷ 資料庫以什麼形式存放一個對象

表的形式,比如一個對象是車,那麼車有的屬性就是表的元素,比如車有牌子,有輪子.這些都是對象的屬性 直接用表來記錄就行了,至於對象的方法 這個肯定不是對象的內容,不用記錄到表裡.那個是代碼..

⑸ iOS開發資料庫存儲能用FMDB直接存儲對象嗎

如果要存儲復雜對象類型的數據, 該對象必須遵循NSCoding協議, 並實現對應代理方法
對象類型實現代理後, 在存儲之前還有一部操作, 是把對象進行歸檔, 歸檔完成才可以使用FMDB進行存儲, 對應類型為BLOB類型,.
如果要直接存儲復雜對象, 不想寫歸檔什麼的玩意, 可以使用一個第三方框架 JRDB , 這個可以直接存儲復雜對象, jrdb是基於FMDB進行的二次封裝框架, 可以試試噢

⑹ 如何將一個SQL資料庫的所有對象保存到另一個資料庫,包括表、視圖、存儲過程、函數···

第一步,備份資料庫;
第二步,新建一資料庫;
第三步,將第一步的資料庫備份文件還原至第二步創建的資料庫中。

⑺ 1. 資料庫中存儲的基本對象是什麼

答案:

資料庫中存儲的基本對象是

熱點內容
陰陽師防禦隊伍怎麼配置 發布:2024-10-10 07:19:52 瀏覽:886
雲存儲測試工具 發布:2024-10-10 07:19:03 瀏覽:464
java的組件 發布:2024-10-10 06:58:30 瀏覽:176
源代碼編譯後的二進制文件 發布:2024-10-10 06:57:40 瀏覽:136
java門戶網站 發布:2024-10-10 06:48:26 瀏覽:991
伺服器多cpu如何協同工作 發布:2024-10-10 06:42:12 瀏覽:997
appium錄制腳本 發布:2024-10-10 06:42:12 瀏覽:604
壓縮彈簧行程 發布:2024-10-10 06:35:50 瀏覽:803
php目錄在哪 發布:2024-10-10 06:30:09 瀏覽:623
安卓手機怎麼屏蔽垃圾號碼 發布:2024-10-10 06:24:32 瀏覽:925