zoukankan      html  css  js  c++  java
  • SQLiteTest

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.IO;
    using System.Data.SQLite;
    namespace SelectTest
    {
        
    class Program
        {
            
    static void Main(string[] args)
            {
                
    string DBFilePath = @"C:\Documents and Settings\Lenovo\桌面\Email\Email.db";
                
    if (!File.Exists (DBFilePath ))
                {
                    Console.WriteLine(
    "文件不存在");
                }
                SQLiteConnection  dbConnection 
    = new SQLiteConnection();
                dbConnection.ConnectionString 
    = 
                    
    @"Data Source = "+DBFilePath ;
                dbConnection.Open();
                SQLiteCommand command 
    = new SQLiteCommand();
                command .Connection 
    =dbConnection ;
                command.CommandText 
    = "SELECT ID ,Status,DateTime from INBOX order by DateTime";

                SQLiteDataReader dr 
    =command .ExecuteReader ();
                
    string strData = string.Empty;

                
    while (dr.Read ())
                {
                    
    string outPut = string.Empty;
                    
    for (int i = 0; i < dr.VisibleFieldCount ; i++)
                    {
                        
                        
    string strType = dr.GetDataTypeName(i);
                        
                        
    if (strType == "Boolean")
                        {
                            strData 
    = dr.GetBoolean(i).ToString();
                        }
                        
    else if (strType == "Text")
                        {
                            strData 
    = dr.GetString(i);
                        }
                        
    else if (strType == "DATETIME")
                        {
                            strData 
    = dr.GetString(i);
                        }
                        
    else
                        {
                            strData 
    = dr.GetValue(i).ToString();
                        }
                        outPut 
    = outPut + "  " + strData;
                    }
                    Console.WriteLine(outPut );
                }
                Console.Read();
                dr.Close();
                dbConnection.Close();
            }
        }
    }

     

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Data.SQLite;
    using System.IO;
    namespace SQLiteTest
    {
        
    class Program
        {
            
    static void Main(string[] args)
            {
                SQLiteConnection connection
    = null;
                
    try
                {
                    
    string databaseFileName = "C:\\hbhbice.db";
                    
    if (!File.Exists(databaseFileName))
                    {
                        SQLiteConnection.CreateFile(databaseFileName);
                    }
                    connection 
    = new SQLiteConnection(
                        
    "Data Source=" + databaseFileName);
                    connection.Open();
                    
    using (SQLiteCommand command = new SQLiteCommand(connection))
                    {
                        command.CommandText 
    = "SELECT * FROM Student";
                        command.ExecuteNonQuery();
                        
    using (SQLiteDataReader reader = command.ExecuteReader())
                        {
                            StringBuilder sb 
    = new StringBuilder();
                            
    while (reader.Read())
                            {
                                sb.Append(
    "ID\r\n" + reader.GetString(0));
                                sb.Append(
    "\r\nName\r\n" + reader.GetString(1));

                            }
                            Console.WriteLine(sb.ToString());
                        }
                    }
                    Console.ReadLine();
                    
                }
                
    catch (Exception E)
                {

                    
    throw E;
                }
                
    finally
                {
                    
    if (connection .State == System.Data.ConnectionState .Open )
                    {
                        connection.Close();
                    }
                }
     
            }
        }
    }
  • 相关阅读:
    从首页看CCS布局
    Community Server专题一:概述Community Server
    datagrid程序增加列的方法
    类的关键字
    base 关键字用于从派生类中访问基类的成员:
    关于CS1.1后台管理页面的研究
    如何:创建同步 HTTP 处理程序
    Community Server专题二:体系结构
    SqlTransaction 类
    单继承与多实现
  • 原文地址:https://www.cnblogs.com/hbhbice/p/1894095.html
Copyright © 2011-2022 走看看