日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

xamarin使用oracle数据库,XamarinSQLite教程在Xamarin.Android项目中使用数据库

發布時間:2023/12/9 Android 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 xamarin使用oracle数据库,XamarinSQLite教程在Xamarin.Android项目中使用数据库 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

XamarinSQLite教程在Xamarin.Android項目中使用數據庫

Xamarin.Android

項目中使用預設數據庫的具體操作步驟如下:

(

1

)創建一個

Xamarin.Android

項目,如

AndroidSQLiteDemo

(

2

)在

AndroidSQLiteDemo

項目的

Resources

文件夾下創建一個

Raw

文件夾。

(

3

)將上一節中創建的

Documents.db

數據庫拖動到

Raw

文件夾中。

(

4

)打開

MainActivity.cs

文件,將

Documents.db

數據庫的內容復制到

/data/data/[your packageName/files/ MyDocuments.db

中,代碼如下:

using?System;

using?Android.App;

using?Android.Content;

using?Android.Runtime;

using?Android.Views;

using?Android.Widget;

using?Android.OS;

using?Android.Support.V7.App;

using?System.IO;

using?System.Text;

namespace?AndroidSQLiteDemo

{

[Activity(Label?=?"@string/app_name",?MainLauncher?=?true,?LaunchMode?=?Android.Content.PM.LaunchMode.SingleTop,?Icon?=?"@drawable/icon")]

public?class?MainActivity?:?AppCompatActivity

{

protected?override?void?OnCreate(Bundle?bundle)

{

base.OnCreate(bundle);

SetContentView(Resource.Layout.main);

var?toolbar?=?FindViewById(Resource.Id.toolbar);

if?(toolbar?!=?null)

{

SetSupportActionBar(toolbar);

SupportActionBar.SetDisplayHomeAsUpEnabled(false);

SupportActionBar.SetHomeButtonEnabled(false);

}

//?Get?our?button?from?the?layout?resource,

//?and?attach?an?event?to?it

var?clickButton?=?FindViewById(Resource.Id.my_button);

clickButton.Click?+=?(sender,?args)?=>

{

var?sqliteFilename?=?"MyDocuments.db";

string?documentsPath?=?System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);?//?Documents?folder

var?path?=?Path.Combine(documentsPath,?sqliteFilename);

Console.WriteLine("數據庫文件的目錄:{0}",path);

if?(!File.Exists(path))

{

var?s?=?Resources.OpenRawResource(Resource.Raw.Documents);

//創建寫入列

FileStream?writeStream?=?new?FileStream(path,?FileMode.OpenOrCreate,?FileAccess.Write);

ReadWriteStream(s,?writeStream);

}

};

}

void?ReadWriteStream(Stream?readStream,?Stream?writeStream)

{

int?Length?=?256;

Byte[]?buffer?=?new?Byte[Length];

int?bytesRead?=?readStream.Read(buffer,?0,?Length);

//?寫入所需字節

while?(bytesRead?>?0)

{

writeStream.Write(buffer,?0,?bytesRead);

bytesRead?=?readStream.Read(buffer,?0,?Length);

}

readStream.Close();

writeStream.Close();

}

}

}

運行程序后,初始狀態如圖

1.31

所示。

輕拍

HELLO WORLD,CLICK ME!

按鈕后,會在輸出窗口輸出以下的內容:

數據庫文件的目錄:

/data/user/0/com.company.AndroidSQLiteDemo/files/MyDocuments.db

此時

Documents.db

數據庫中的內容就會復制到

MyDocuments.db

文件中。

總結

以上是生活随笔為你收集整理的xamarin使用oracle数据库,XamarinSQLite教程在Xamarin.Android项目中使用数据库的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。