毕业设计中C#操作数据库

毕业设计中C#操作数据库

ID:306726

大小:416.50 KB

页数:11页

时间:2017-07-21

毕业设计中C#操作数据库_第1页
毕业设计中C#操作数据库_第2页
毕业设计中C#操作数据库_第3页
毕业设计中C#操作数据库_第4页
毕业设计中C#操作数据库_第5页
资源描述:

《毕业设计中C#操作数据库》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库

1、在做毕业设计,同时也在学习C#用到DataGridView时开始觉得很难,经过朋友的帮助和自己的努力,稍微的明白了一些,现在就把我写的方法写下来,大家一起学习,写的不好的地方也请指证。  DataGridView做了新的数据显示控件加入到了.Net05中,其强大的编辑能力让其成为了数据显示中必不可少的控件。目前对于DataGridView中的更新讲的挺多的,但直接的插入数据好像讲的不是太多,下面就以我的例子说明一下。  1、首先新建一个项目。  2、建立一个数据库连接类LinkDataBase。因为数据库操作有很多都是重复性工作,

2、所以我们写一个类来简化对数据库的操作。using System;using System.Collections.Generic;using System.Text;using System.Data;using System.Data.SqlClient;using System.Data.Sql;namespace Test...{    class LinkDataBase    ...{        //设置连接字符串        private string strSQL;        //与数据库连接      

3、  private string connectionString = "Data Source=Localhost;Initial Catalog=Test;Integrated Security=True";        private SqlConnection myConnection;        private SqlCommandBuilder sqlCmdBld;        private DataSet ds = new DataSet();        private SqlDataAdapter d

4、a;        public LinkDataBase()        ...{        }        //根据输入的SQL语句检索数据库数据        public DataSet SelectDataBase(string tempStrSQL, string tempTableName)        ...{            this.strSQL = tempStrSQL;            this.myConnection = new SqlConnection(connectionSt

5、ring);            this.da = new SqlDataAdapter(this.strSQL, this.myConnection);            this.ds.Clear();            this.da.Fill(ds, tempStrSQL);            //返回填充了数据的DataSet,其中数据表以tempTableName给出的字符串命名            return ds;        }        //数据库数据更新(传DataSet和DataT

6、able的对象)        public DataSet UpdateDataBase(DataSet changedDataSet, string tableName)        ...{            this.myConnection = new SqlConnection(connectionString);            this.da = new SqlDataAdapter(this.strSQL, this.myConnection);            this.sqlCmdBld =

7、 new SqlCommandBuilder(da);            this.da.Update(changedDataSet, tableName);            //返回更新过的数据库表            return changedDataSet;        }        //检索数据库数据(传字符串,直接操作数据库)        public DataTable SelectDataBase(string tempStrSQL)        ...{            this.my

8、Connection = new SqlConnection(connectionString);            DataSet tempDataSet = new DataSet();            this.da = new S

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。