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 即可~
相关文档:
a = “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\数据库.mdb;Password=管理员密码;User ID=管理员帐号;Jet OLEDB:Database Password=数据库密码;Jet OLEDB:System database=d:\system.MDW;” ' 此处用户帐户必须具有管理员权限才行,此处是指连接需要压缩的数据库的连接代码.
b = &ldq ......
C#使用System.Data.OracleClient连接Oracle数据库。之前在WinXP上正常运行的程序移植到 Windows 2008 x64上之后就连不上数据库了,错误信息如下:
尝试加载 Oracle客户端库时引发BadImageFomatException。如果在安装32位Oracle客户端组件的情况下以64位模式运行,将出现此问题。
错误原因是原来WinXP机子上所安装的Orac ......
这个逻辑关系乍看起来比较复杂,弄清楚了就好!
有两个表,
student(
id,
name,
primary key (id)
);
studentInfo(
id,
age,
address,
foreign key(id) references outTable(id) on delete cascade on update cascade
);
当我们删除student表的时候自然希望studentInfo里的相关信息也被删除,这就是外键起作用 ......
Magento是在Zend Framework的基础上搭建而来,有两种方式可以从Magento的collection获得真正的SQL语句。
以 Mage::getResourceModel('reports/product_collection') 为例:
1
$collection=Mage::getResourceModel('reports/product_collection');
......