方法一:
(1)建立sqlconnection 例項
(2)建立sqldataadapter 例項
(3)建立dataset或datatable的例項
(3)使用fill方法將資料庫的表填充到dataset或datatable的表中
(4)利用datagridview或者其它空間編輯或顯示資料
(5)使用update方法更新資料庫
code:
sqlconnection conn;
sqldataadapter dastu;
dataset ds;
datagridview datagridview1=new datagridview ();
conn = new sqlconnection(@"data source=.\sqlexpress;" +
@"attachdbfilename=|datadirectory|\grademanagementsystem.mdf;" +
"integrated security=true;connect timeout=30;user instance=true");
conn.open();//開啟連線
//將表student填充到相應的datagribview1中
//執行以下語句後介面卡僅包含selectcommand
dastu = new sqldataadapter("select * from student", conn);
cmdbuilder = new sqlcommandbuilder(dastu);
dastu.fill(ds, "student");
datagridview1.datasource = ds.tables["student"];
conn.close();//關閉連線
當datagridview1中的資料更改後,只需執行
dastu.update(ds, "student");
即可更改到資料庫中。
資料庫表 庫操作
一 庫的管理 1 建立庫 create database if not exist 庫名 2 庫的修改 rename database 舊庫名 to 新庫名 修改資料庫的字符集 alter database 資料庫名稱 character set 字符集名稱 3 庫的刪除 drop database...
MySQL 資料庫表與資料的操作
create database 資料庫名 charset utf8 drop database 資料庫名 use 資料庫名 select database create table 表名 列及型別 如 create table students id int auto increment prima...
資料庫與表的操作語句
例 create database if not exists intheima use itheima create table if not exists student id int unsigned primary key auto increment comment 學號 name var...