Sqlite 添加、查询

前端之家收集整理的这篇文章主要介绍了Sqlite 添加、查询前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CommonClassLibary;
using System.Data.sqlite;
namespace TEST
{
public partial class Frmsqlite : Form
{
string databaseName = string.Empty;
string con = string.Empty;
public Frmsqlite()
{
InitializeComponent();
databaseName = AppDomain.CurrentDomain.BaseDirectory + "\\sam_db.sam";
con = string.Format("Data Source={0};password=sam",databaseName);
}
/// <summary>
/// 添加
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender,EventArgs e)
{
string sql = @"insert into DataBaseInfo ([DBAddress],[DBName],[DBUserName],[DBUserPwd])
values (@dbAddress,@dbName,@dbUser,@dbPwd)";
sqliteParameter[] para = new sqliteParameter[4];

for (int i = 0; i < para.Length; i++)
{
para[i] = new sqliteParameter();
}
para[0].ParameterName = "@dbAddress";
para[0].DbType = DbType.String;
para[0].Direction = ParameterDirection.Input;
para[0].Value = txt_dbAdress.Text;

para[1].ParameterName = "@dbName";
para[1].DbType = DbType.String;
para[1].Direction = ParameterDirection.Input;
para[1].Value = txt_dbName.Text;

para[2].ParameterName = "@dbUser";
para[2].DbType = DbType.String;
para[2].Direction = ParameterDirection.Input;
para[2].Value = txt_dbUser.Text;

para[3].ParameterName = "@dbPwd";
para[3].DbType = DbType.String;
para[3].Direction = ParameterDirection.Input;
para[3].Value = txt_dbPwd.Text;

CommonClassLibary.sqlHelper.sqliteHelper.ExecuteNonQuery(con,sql,CommandType.Text,para);
}
//查询
private void button2_Click(object sender,EventArgs e)
{
string strsql = "select * from DataBaseInfo ";
DataTable DT= CommonClassLibary.sqlHelper.sqliteHelper.ExecuteDataSet(con,strsql,CommandType.Text).Tables[0];
this.dataGridView1.DataSource = DT;


}

}
}
原文链接:https://www.f2er.com/sqlite/199436.html

猜你在找的Sqlite相关文章