
1、首先在电脑中打开SQL之后,打开navicate,新建一个查询,如下图所示。
2、然后在打开的页面中,使用use命令,切换到要查询的数据库:use test,如下图所示。
3、接着使用desc命令加上表名来查看表结构:desc jingyan,如下图所示。
4、执行后,就可以看到jingyan表的表结构了,如下图所示就完成了。
using System
using System.Collections.Generic
using System.ComponentModel
using System.Data
using System.Drawing
using System.Text
using System.Windows.Forms
//引用命名空间
using System.Data.OleDb
namespace 代码绑定
{
public partial class Form1 : Form
{
//添加绑定对象,就是前面学过的Ado.net对象
OleDbDataAdapter da//数据适配器
DataSet ds//数据集
OleDbCommandBuilder DCB//命令管理器
BindingSource bs//绑定源对象
public Form1()
{
InitializeComponent()
}
private void Form1_Load(object sender, EventArgs e)
{
//连接字符串
string strCon = "Provider=Microsoft.jet.oledb.4.0data source=" + AppDomain.CurrentDomain.BaseDirectory + "student.mdb "
//添加查询语句
string StrSelect = "select 学号,姓名,性别 from dzsw1"
//初始化数据适配器及数据集
da = new OleDbDataAdapter(StrSelect ,strCon)
ds = new DataSet()
//填充数据到数据集
da.Fill(ds, "dzsw")
DCB = new OleDbCommandBuilder(da)
//初始化绑定源对象
bs = new BindingSource()
bs.DataSource = ds.Tables[0]
//绑定DataGridView
dataGridView1.DataSource = bs
//绑定 文本框
textBox1.DataBindings.Add("Text", bs, "姓名")
//绑定 列表框
listBox1.DataSource = bs
listBox1.DisplayMember = "姓名"
//绑定组合框
comboBox1.DataSource = bs
comboBox1.DisplayMember = "姓名"
}
private void button2_Click(object sender, EventArgs e)
{
//指针后移
bs.Position++
}
private void button1_Click(object sender, EventArgs e)
{
//指针前移
bs.Position--
}
private void button3_Click(object sender, EventArgs e)
{
//更新数据
da.Update(ds.Tables[0])
}
}
}
create table Department(
departId char(2) not null primary key ,
departName varchar(30) not null
)
create table Speciality
(
specId char(4) not null primary key ,
specNamevarchar(30) not null ,
departIdchar(2) null ,
foreign key(departId) references Department(departId)
)
create table Class
(
classId char(8) not null primary key ,
className varchar(30) null ,
specId char(4) null ,
departIdchar(2) null ,
remark varchar(30) null ,
foreign key(specId) references Speciality(specId) ,
foreign key(departId) references Department(departId)
)
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)