5.24數(shù)據(jù)庫應(yīng)用

usingUnityEngine;

usingSystem.Collections;

usingUnityEngine.UI;

usingMono.Data.Sqlite;

publicclassLoginScript:MonoBehaviour{

public InputField? accountText;

public? InputField? passwordText;

Text?? showText;

SqliteConnection?? connection;

SqliteCommand?? command;

SqliteDataReader? reader;

string??? dbPath;

voidStart( ){

showText=GameObject.Find("ShowText").GetComponent<Text>( );

dbPath="DataSource="+Application.streamingAssetsPath+"/UserDatabase.sqlite";

connection=new? SqliteConnection(dbPath);

connection.Open( );

command=connection.CreateCommand( );

}


publicvoidButtonPressed( ){

Login( );

}

public void ButtonPressed_1( ){

Reset( );

}

public void ButtonPressed_2( ){

Registered( );

print("sfd");

}

public void Login( ){

string account=accountText.text;

string password=passwordText.text;

if(account.Length>0&&password.Length>0){

//找到與數(shù)據(jù)庫中與account相同的uname

command.CommandText="SELECT*FROM UserTable WHERE uname="+"'"+account+"'";

object? obj=command.ExecuteScalar( );

if(obj!=null){

if(password==obj.ToString()){

print("sdf");

showText.text="登陸成功";

}else{

showText.text="密碼錯(cuò)誤";

}

}else{

showText.text="用戶名不存在";

}

}

}

voidReset( ){

accountText.text="";

passwordText.text="";

showText.text="";

command.CommandText="DELETE FROM UserTable WHERE? rowid>0";

try{

command.ExecuteNonQuery();

}catch(SqliteExceptionex){

print(ex.Message);

}

}

voidRegistered( ){

command.CommandText="INSERTINTOUserTable(pwd,uname)VALUES("+"'"+passwordText.text+"'"+","+"'"+accountText.text+"'"+")";

command.ExecuteNonQuery( );

print("5612");

}

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 1. Java基礎(chǔ)部分 基礎(chǔ)部分的順序:基本語法,類相關(guān)的語法,內(nèi)部類的語法,繼承相關(guān)的語法,異常的語法,線程的語...
    子非魚_t_閱讀 34,734評(píng)論 18 399
  • //Clojure入門教程: Clojure – Functional Programming for the J...
    葡萄喃喃囈語閱讀 4,051評(píng)論 0 7
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,578評(píng)論 19 139
  • usingUnityEngine; usingSystem.Collections; usingMono.Data...
    胤醚貔貅閱讀 167評(píng)論 0 0
  • 下午與女兒一起出去,看到一輛車子因?yàn)閬y停車被交警貼罰單了,女兒很細(xì)心,看到罰單上的車子顏色與實(shí)際不符,明明是一輛黑...
    莜薇閱讀 487評(píng)論 0 0

友情鏈接更多精彩內(nèi)容