易截截图软件、单文件、免安装、纯绿色、仅160KB

C#连接Access和SQL Server数据库

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Str
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
/*
* connect to Sql Server
*/
string strConnection = "Data Source=ZRQ-PC;";
strConnection+="Initial Catalog=master;Integrated Security=True";
SqlConnection objConnection = new SqlConnection(strConnection);
objConnection.Open();
objConnection.Close();
/**************************************************************/
/*
* connect to access table
*/
//string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;";
//strConnection += @"Data Source=C:\Users\ZRQ\Documents\STU.accdb";
//OleDbConnection objConnection = new OleDbConnection(strConnection);
//objConnection.Open();
//objConnection.Close();
/**************************************************************/
/*
*as for connect to Oracle or MySql 等我学了再说吧……(*^__^*)
*/
}
}
}
其中的简易办法:
在“服务器资源管理器”中选择要连接的数据,then看它的属性中Name,copy to strConnection 即可~


相关文档:

C#使用XML


用的是一种很笨的方法,但可以帮助初学者了解访问XML节点的过程。
已知有一个XML文件(bookstore.xml)如下:
 
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
    <title>Oberon's Legacy</title>
 &nbs ......

操作数据库结构的常用Sql命令(2)

操作数据库结构的常用Sql
下面是Sql Server 和 Access 操作数据库结构的常用Sql,内容由海娃整理,不正确与不完整之处还请提出,谢谢。
新建表:
create table [表名]
(
[自动编号字段] int IDENTITY (1,1)  PRIMARY KEY ,
[字段1] nVarChar(50) default '默认值' null ,
[字段2] ntext null ,
[字段3] dateti ......

SQL里的主键和外键

这个逻辑关系乍看起来比较复杂,弄清楚了就好!
有两个表,
student(
id,
name,
primary key (id)
);
studentInfo(
id,
age,
address,
foreign key(id) references outTable(id) on delete cascade on update cascade
);
当我们删除student表的时候自然希望studentInfo里的相关信息也被删除,这就是外键起作用 ......

sql server中常见的函数的用法

SQL字符串函数http://www.cnblogs.com/virusswb/archive/2008/09/10/1288576.html
select语句中只能使用sql函数对字段进行操作(链接sql server),
select 字段1 from 表1 where 字段1.IndexOf("云")=1;
这条语句不对的原因是indexof()函数不是sql函数,改成sql对应的函数就可以了。
left()是sql函数。
select 字 ......

sql执行顺序

标准的 sql 的解析顺序为: (1).from 子句  组装来自不同数据源的数据
 (2).where 子句  基于指定的条件对记录进行筛选
 (3).group by 子句  将数据划分为多个分组 
 (4).使用聚合函数进行计算
 (5).使用 having  ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号