乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      SQLite B/S使用(一)

       偷心無(wú)痕 2016-01-15

      SQLite屬于一個(gè)輕量級(jí)的數(shù)據(jù)庫(kù),但是功能絕不遜于SQl Server 、Access等

      1.去網(wǎng)上下載一個(gè)System.Data.SQLite.DLL在要用項(xiàng)目中添加引用,再打開(kāi)命名空間using System.Data.SQLite;

      下載地址:http://files.cnblogs.com/sjrhero/System.Data.SQLite.rar

      2.下面就是下載一個(gè)SQLite工具我使用的SQLite工具是SQLiteManager,創(chuàng)建一個(gè)數(shù)據(jù)庫(kù)擴(kuò)展名為*.sqlite,再創(chuàng)建表跟SQL Server的Sql語(yǔ)句基本上是一樣的(目前沒(méi)有發(fā)現(xiàn)在不一樣,還是第一次用)

      3.使用創(chuàng)建的SQLite數(shù)據(jù)庫(kù)(其實(shí)跟使用SQL Server數(shù)據(jù)庫(kù)沒(méi)有什么區(qū)別,第一次使用)以下是第一次使用的代碼:

       

      protected void Button1_Click(object sender, EventArgs e)
      {
      SQLiteConnection sqlcon = new SQLiteConnection("Data Source=|DataDirectory|mydatabase.sqlite;Pooling=true;FailIfMissing=false");
      sqlcon.Open();
      SQLiteCommand cmd = new SQLiteCommand("select * from testTB where userName = '用戶名'", sqlcon);
      SQLiteDataReader sdr = cmd.ExecuteReader();
      while (sdr.Read())
      {
      Response.Write(sdr[0].ToString()+"<br />");
      }
      sdr.Close();
      //以下是使用SQLiteHelper
      DataTable dt = SQLiteHelper.ExecuteDataset(sqlcon, "select * from testTB where userName = '用戶名'").Tables[0];
      if (dt.Rows.Count>0)
      {
      foreach (DataRow item in dt.Rows)
      {
      Response.Write(item["userName"].ToString());
      }
      }
      dt.Dispose();
      sqlcon.Close();
      }

      上面的Data Source=|DataDirectory|mydatabase.sqlite這是使用的相對(duì)路徑將它放在Web應(yīng)用項(xiàng)目的App_Data目錄,|DataDirectory|  就代表這個(gè)目錄的位置,后面的就是文件名(兩堅(jiān)也是必須帶上)。目前只在B/S模式下測(cè)試路徑問(wèn)題,絕對(duì)路徑就不用帶|DataDirectory|了。C/S模式下還沒(méi)有驗(yàn)證 示例如下: 

      connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|

      AttachDbFilename=|DataDirectory|    這個(gè)直接定位App_Data文件夾。

      下面是在web.config中配置的使用

       

      <configuration>
      <configSections>
      <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null />
      </configSections>
      <dataConfiguration defaultDatabase="


      "
      >
      <providerMappings>
      <add databaseType="EntLibContrib.Data.SQLite.SQLiteDatabase, EntLibContrib.Data.SqLite, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null"
      name
      ="System.Data.SQLite" />
      </providerMappings>
      </dataConfiguration>
      <connectionStrings>
      <add name="sqlite" connectionString="Data Source=|DataDirectory|\db;Pooling=true;FailIfMissing=false"
      providerName
      ="System.Data.SQLite" />
      </connectionStrings>
      </configuration>

       以下是別人初學(xué)的時(shí)候的示例:

       

      private void button1_Click(object sender, EventArgs e)
      {
      //數(shù)據(jù)庫(kù)路徑
      string datasource = "data.db";
      //創(chuàng)建數(shù)據(jù)庫(kù)
      SQLiteConnection.CreateFile(datasource);
      //創(chuàng)建連接,默認(rèn)密碼為admin
      SQLiteConnection conn = new SQLiteConnection("Data Source=data.db;password=admin");
      //建立連接
      conn.Open();
      //創(chuàng)建命令
      SQLiteCommand cmd = new SQLiteCommand();
      //設(shè)置連接
      cmd.Connection = conn;
      //設(shè)置命令字:創(chuàng)建表
      cmd.CommandText = "CREATE TABLE GpsPoints(ID integer,B numeric,L numeric,H numeric)";
      //執(zhí)行sql語(yǔ)句,不需要返回值。
      cmd.ExecuteNonQuery();
      //讀取id列最大值
      int next_id = 0;
      cmd.CommandText = "select max(id) from GpsPoints";
      //讀取結(jié)果
      SQLiteDataReader reader = cmd.ExecuteReader();
      //如果沒(méi)取到,空數(shù)據(jù),則id設(shè)置為0
      if (reader.IsDBNull(0)) next_id = 0;
      //反之最大值+1
      else next_id = int.Parse(reader[0].ToString()) + 1;
      //關(guān)閉讀取
      reader.Close();
      //創(chuàng)建命令,插入數(shù)據(jù),這里例子沒(méi)使用SQLiteParameter
      cmd.CommandText = "insert into GpsPoints values(" + next_id.ToString() + ",123.456,123.456,123.456)";
      cmd.ExecuteNonQuery();
      cmd.CommandText = "select max(id) from GpsPoints";
      reader = cmd.ExecuteReader();
      MessageBox.Show(reader[0].ToString());
      conn.Close();
      }

       

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多