C#连接到SQL Server,SQLite数据库
//sqlite 数据库string uploadDate = System.DateTime.Now.ToShortDateString().ToString();
string uploadTime = System.DateTime.Now.ToLongTimeString().ToString();
SQLiteConnection conn = null;
string dbPath = "Data Source =" + "C:/sqlite" + "/数据测试.db";
conn = new SQLiteConnection(dbPath);//创建数据库实例,指定文件位置
conn.Open();//打开数据库,若文件不存在会自动创建
string sql = "CREATE TABLE IF NOT EXISTS '" + "温度" + uploadDate + "' (日期 varchar(6), 时间 varchar(6), 温度 varchar(6));";//建表语句
SQLiteCommand cmdCreateTable = new SQLiteCommand(sql, conn);
cmdCreateTable.ExecuteNonQuery();//如果表不存在,创建数据表
SQLiteCommand cmdInsert = new SQLiteCommand(conn);
cmdInsert.CommandText = "INSERT INTO '" + "温度" + uploadDate + "'VALUES('" + uploadDate + "','" + uploadTime + "','" + wendu + "')";//插入几条数据
cmdInsert.ExecuteNonQuery();
conn.Close();
页:
[1]