教程集 www.jiaochengji.com
教程集 >  脚本编程  >  C语言  >  正文 asp.net C sqlite数据库的方法

asp.net C sqlite数据库的方法

发布时间:2018-10-14   编辑:jiaochengji.com
教程集为您提供asp.net C sqlite数据库的方法等资源,欢迎您收藏本站,我们将为您提供最新的asp.net C sqlite数据库的方法资源

select * from person";
  SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
  DataSet ds = new DataSet();
  da.Fill(ds);
  dataGridView1.DataSource = ds.Tables[0];
  mycon.Close();

你需要下载sqlite的源代码
    http://www.sqlite.org/sqlite-3.6.6.2.tar.gz
    #tar xf sqlite-3.6.6.2.tar.gz
    #cd sqlite-3.6.6.2.tar.gz
    #./configure prefix=/usr
    #make
    #make install

    然后。。就可以开始第一步尝试了。在c中访问sqlite数据库
  
    c代码如下:

    #include <stdio.h>
    #include <stdlib.h>
    #include <sqlite3.h>
    int main( void )
    {
        sqlite3 *db=NULL;
        char *zErrMsg = 0;
        int rc;
        rc = sqlite3_open("zieckey.db", &db);
        if( rc )
        {
            fprintf(stderr, "Can't open sqlite: %sn", sqlite3_errmsg(db));
            sqlite3_close(db);
            exit(1);
        }
      else printf("open sqlite successn");
        sqlite3_close(db); //关闭数据库
        return 0;
     }
  
   将此文件另存为sql.c
     可以链接sqlite动态库
     #gcc sql.c -lsqlite3 -o sql
     也可以直接连接静态库
   #gcc sql.c /usr/lib/libsqlite3.a -lpthread -o sql

   执行
     #./sql
     会显示
     open sqlite success

     恭喜你。sqlite可以正常工作了

下面可以工作了,我们看更详细的做法

// checkusername.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"

//sqlite3_exec的重载,避免穿那么多用不到的参数(纯C没有重载)
SQLITE_API int sqlite3_exec(sqlite3* db,const char *sql)
{
 char *zErrMsg = 0;
 return sqlite3_exec(db, sql, NULL, NULL, &zErrMsg);
}

int _tmain(int argc, _TCHAR* argv[])
{
 printf("Contenttype:text/htmlnn"); //根据HTTP协议,这里一定要有个空行。

 sqlite3 *db;
    int rc;
    rc = sqlite3_open("D:greeninstalltinywebserverwwwrootrp.db3", &db);
    if( rc!=SQLITE_OK  )
 {
        printf( "Can't open database: %sn", sqlite3_errmsg(db));
        sqlite3_close(db);
        return -1;
    }
 /*rc = sqlite3_exec(db, "Insert into T_User(username,password) values('admin','123')");
 if( rc !=SQLITE_OK )
 {
        printf("Can't open database: %sn", sqlite3_errmsg(db));
        sqlite3_close(db);
        return -1;
    }*/

    sqlite3_stmt *pStmt;
   
    //建立过程
 rc = sqlite3_prepare(db, "select * from T_User where password=?", -1, &pStmt, 0);
    if(rc != SQLITE_OK){
        printf( "execute sql error: %sn", sqlite3_errmsg(db));
        sqlite3_close(db);
        return -1;
    }
   
    //绑定参数
 if(sqlite3_bind_text(pStmt, 1, "123",-1,SQLITE_STATIC) != SQLITE_OK){
        printf( "sqlite3_bind_int error: %sn", sqlite3_errmsg(db));
        goto test_exit;
    }
   
    // 多次执行过程
    while(sqlite3_step(pStmt)!=SQLITE_DONE){
  const unsigned char* name = sqlite3_column_text(pStmt,1);
     const unsigned char* password = sqlite3_column_text(pStmt,2);
  printf("%s=%sn",name,password);
    }
   
test_exit:   
    if(sqlite3_finalize(pStmt) != SQLITE_OK){
        printf( "testPrepareStmt-sqlite3_finalize");
    }

    sqlite3_close(db);
 printf("ok");
 return 0;
}

您可能感兴趣的文章:
SQLite简介
SQLite数据库的使用
asp.net C sqlite数据库的方法
SQLite 60分钟入门教程
php操作SQLite类的代码分享
SQLLite操作百万级数据之优化篇
Python(SQLite)executescript用法(
asp.net EntityFramework 6连接Sqlite数据库例子
Python中SQLite的简单应用
SQLite命令学习

[关闭]
~ ~