数据库开发个人总结(ADO.NET小结) -ASP.NET应用-knowsky首页源码字体下载软件电脑书|
素材图片模版
壁纸矢量酷站图标笔刷纹理|小游戏博客QQ表情投票计数器小说
首页|网络编程|站长之家|网页制作|图形图象|操作系统|冲浪宝典|
软件教学|网络办公|手机|邮件
系统|
网络安全|认证考试
ASP源码 | .Net源码 |
PHP源码 |
JSP源码 | JAVA源码 | CGI源码 |
VB源码 | C++源码 |
Delphi源码
| PB源码 | VF源码 | 汇编 | 服务器
迅雷 | 电驴 | Win7 | QQ空间 | 输入法 | Ghost | Word | Excel | asp | php | Sql |
Dreamweaver |
Javascript | css | photoshop | fireworks | Flash
-
当前位置 > 网站建设 > 网络编程 > ASP.
NET应用
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,
压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
数据库开发个人总结(ADO.NET小结)
发表日期:2007-4-12 |
-
一.用SqlConnection连接SQL Server
1..加入命名空间
using System.Data.SqlClient;
2.连接数据库
SqlConnection myConnection = new SqlConnection();
myConnection.ConnectionString = "user
id=sa;passWord=sinofindb;initial catalog=test;data
source=127.0.0.1;Connect Timeout=30";
myConnection.Open();
改进(更通用)的方法:
string MySQLConnection="user id=sa;password=sinofindb;Database
=test;data source=127.0.0.1;Connect Timeout=30";
SqlConnection myConnection = new SqlConnection(MySqlConnection);
myConnection.Open();
二。用OleDbConnection连接
1.加入命名空间
using System.Data.OleDb;
2.连接
sql server
string MySqlConnection="PRovider=SQLOLEDB;Data
Source=localhost;Initial Catalog=test;Integrated Security=SSPI;";
SqlConnection myConnection = new SqlConnection(MySqlConnection);
myConnection.Open();
3.连接access(可通过建立.udl文件获得字符串)
string MySqlConnection="Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\db2000.mdb;
Persist Security Info=False;
4.连接Oracle(也可通过OracleConnection连接)
string MySqlConnection="Provider=MSDAORA;Data Source=db; user
id=sa;password=sinofindb";
三.创建Command对象
1.SqlCommand 构造函数
①初始化 SqlCommand 类的新实例。public SqlCommand();
SqlCommand myCommand = new SqlCommand();
②初始化具有查询文本的 SqlCommand 类的新实例。public SqlCommand(string);
String mySelectQuery = "SELECT * FROM mindata";
SqlCommand myCommand = new SqlCommand(mySelectQuery);
③初始化具有查询文本和 SqlConnection 的SqlCommand类实例。
Public SqlCommand(string, SqlConnection);
String mySelectQuery = "SELECT * FROM mindata";
string myConnectString = "user
id=sa;pass
word=;database=test;server=mySQLServer";
SqlConnection myConnection = new SqlConnection(myConnectString);
SqlCommand myCommand = new SqlCommand(mySelectQuery,myConnection);
④初始化具有查询文本、SqlConnection 和 Transaction 的 SqlCommand 类实例。
public SqlCommand(string, SqlConnection, SqlTransaction);
SqlTransaction myTrans = myConnection.BeginTransaction();
String mySelectQuery = "SELECT * FROM mindata";
string myConnectString = "user
id=sa;password=;database=test;server=mySQLServer";
SqlConnection myConnection = new SqlConnection(myConnectString);
SqlCommand myCommand = new SqlCommand(mySe