第一步,先建立與資料庫的連線
第二步,在program.cs裡面寫程式
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CaterDal
{
public static class SqliteHelper
//從配置文字中讀取連線字串
private static string connStr = "Data Source=資料庫的名稱;Initial Catalog=SWALL;User ID=SA;Password=666";//是這個資料庫沒錯吧?
public static DataTable GetDataTable(string sql,params SqlParameter[] ps)
using (SqlConnection conn=new SqlConnection(connStr))
//構造介面卡物件
SqlDataAdapter pter=new SqlDataAdapter(sql,conn);
//構造資料表,用於接收查詢結果
DataTable dt=new DataTable();
//新增引數
pter.SelectCommand.Parameters.AddRange(ps);
//執行結果
pter.Fill(dt);
//返回結果集
return dt;
}
第三步,在專案裡面寫程式
private void button4_Click(object sender, EventArgs e)
DataTable Dt = SqliteHelper.GetDataTable("select * from jjjj");
dataGridView1.DataSource = Dt;
DataTable Dt = SqliteHelper.GetDataTable("select * from lishiji");
Form1.cs專案名
FROM2.CS專案名
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Data.OleDb;
using CaterDal;
namespace sqlssss
public partial class Form2 : Form
public Form2()
InitializeComponent();
private void button1_Click(object sender, EventArgs e)
DataTable Dt = new DataTable();
Dt = SqliteHelper.GetDataTable("select * from lishiji");
DgvQueue.DataSource = Dt;
第一步,先建立與資料庫的連線
第二步,在program.cs裡面寫程式
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CaterDal
{
public static class SqliteHelper
{
//從配置文字中讀取連線字串
private static string connStr = "Data Source=資料庫的名稱;Initial Catalog=SWALL;User ID=SA;Password=666";//是這個資料庫沒錯吧?
public static DataTable GetDataTable(string sql,params SqlParameter[] ps)
{
using (SqlConnection conn=new SqlConnection(connStr))
{
//構造介面卡物件
SqlDataAdapter pter=new SqlDataAdapter(sql,conn);
//構造資料表,用於接收查詢結果
DataTable dt=new DataTable();
//新增引數
pter.SelectCommand.Parameters.AddRange(ps);
//執行結果
pter.Fill(dt);
//返回結果集
return dt;
}
}
}
}
第三步,在專案裡面寫程式
private void button4_Click(object sender, EventArgs e)
{
DataTable Dt = SqliteHelper.GetDataTable("select * from jjjj");
dataGridView1.DataSource = Dt;
}
}
}
private void button4_Click(object sender, EventArgs e)
{
DataTable Dt = SqliteHelper.GetDataTable("select * from jjjj");
dataGridView1.DataSource = Dt;
}
}
}
private void button4_Click(object sender, EventArgs e)
{
DataTable Dt = SqliteHelper.GetDataTable("select * from lishiji");
dataGridView1.DataSource = Dt;
}
}
}
Form1.cs專案名
1private void button4_Click(object sender, EventArgs e)
{
DataTable Dt = SqliteHelper.GetDataTable("select * from jjjj");
dataGridView1.DataSource = Dt;
}
}
}
FROM2.CS專案名
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
using CaterDal;
namespace sqlssss
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DataTable Dt = new DataTable();
Dt = SqliteHelper.GetDataTable("select * from lishiji");
DgvQueue.DataSource = Dt;
}
}
}