c# sqlite.-凯发app官方网站

凯发app官方网站-凯发k8官网下载客户端中心 | | 凯发app官方网站-凯发k8官网下载客户端中心
  • 博客访问: 29835552
  • 博文数量: 230
  • 博客积分: 2868
  • 博客等级: 少校
  • 技术积分: 2223
  • 用 户 组: 普通用户
  • 注册时间: 2009-10-08 21:48
个人简介

live & learn

文章分类

(230)

  • (4)
  • (5)
  • (0)
  • (2)
  • (6)
  • (9)
  • (0)
  • (5)
  • (2)
  • (1)
  • (49)
  • (17)
  • (7)
  • (6)
  • (0)
  • (0)
  • (4)
  • (0)
  • (113)
文章存档

(2)

(5)

(15)

(42)

(24)

(13)

(1)

(5)

(58)

(56)

(9)

我的朋友
相关博文
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·

分类: c#/.net

2017-08-07 09:28:41

1  下载sqlite  .net
2  cope sqlite.data.dll 到可执行程序目录下,
3 添加引用,copy local属性为true;
4 编写代码:
 

点击(此处)折叠或打开

  1. using system;
  2. using system.collections.generic;
  3. using system.componentmodel;
  4. using system.data;
  5. using system.drawing;
  6. using system.linq;
  7. using system.text;
  8. using system.windows.forms;
  9. using system.data;
  10. using system.data.sqlite;

  11. namespace mac_and_deviceid
  12. {

  13.     public partial class form1 : form
  14.     {
  15.         public form1()
  16.         {
  17.             initializecomponent();
  18.         }

  19.         private void label1_click(object sender, eventargs e)
  20.         {

  21.         }

  22.         private void buttoncreate_click(object sender, eventargs e)
  23.         {
  24.             sqliteconnection.clearallpools();
  25.             sqliteconnection.createfile("userdata.db");
  26.             sqliteconnection sqlcon = new sqliteconnection("data source=userdata.db");
  27.             sqlcon.open();
  28.             sqlitecommand cmd = new sqlitecommand();
  29.             cmd.connection = sqlcon;
  30.             //-------
  31.             cmd.commandtext = "create table users (userid int primary key,username varchar(100) not null,userpassword varchar(100) not null)";
  32.             
  33.             cmd.executenonquery();
  34.             //--------
  35.             for (int i = 0; i < 100; i)
  36.             {
  37.                 cmd.commandtext = "insert into users (userid,username,userpassword) values (" i ",'testuser_" i "','" datetime.now.tostring().replace(" ", "-").replace(":", "-") "')";
  38.                 cmd.executenonquery();
  39.             }
  40.             messagebox.show("create table and insert data");
  41.             //--------
  42.             cmd.commandtext = "select username from users where userid=1";
  43.             cmd.connection = sqlcon;
  44.             string tempusername = tempusername = cmd.executescalar().tostring();
  45.             textboxguid.text = tempusername;
  46.             messagebox.show("get user name:{0}", tempusername);
  47.             //message("tempusername={0}", tempusername);

  48.             //
  49.             cmd.commandtext = "select * from users ";
  50.             cmd.connection = sqlcon;
  51.             sqlitedatareader sdrinfo = cmd.executereader();
  52.             if (sdrinfo != null)
  53.             {
  54.                 int userid = 0;
  55.                 string username = string.empty;
  56.                 string userpassword = string.empty;
  57.                 while (sdrinfo.read())
  58.                 {
  59.                     userid = convert.toint32(sdrinfo["userid"]);
  60.                     username = sdrinfo["username"].tostring();
  61.                     userpassword = sdrinfo["userpassword"].tostring();
  62.                 }
  63.             }
  64.             sdrinfo.close();
  65.             sdrinfo.dispose();


  66.             cmd.commandtext = "update users set userpassword='linxiang'";
  67.             cmd.connection = sqlcon;
  68.             cmd.executenonquery();
  69.             

  70.             //
  71.             sqlcon.close();
  72.             sqlcon.dispose();

  73.             textboxmac.text = "12-34-56-78-96";
  74.         }
  75.     }
  76. }
 编译成功,然后执行会报错:
 在项目中增加app.config:

 
   
   
 




 如果没有用,设置项目属性的设置项,增加字符串_connectionstring 内容 configurationmanager.appsettings["connectionstring"]

阅读(669) | 评论(0) | 转发(0) |
0

上一篇:

下一篇:

给主人留下些什么吧!~~
")); function link(t){ var href= $(t).attr('href'); href ="?url=" encodeuricomponent(location.href); $(t).attr('href',href); //setcookie("returnouturl", location.href, 60, "/"); }
网站地图