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 即可~
相关文档:
我在将Excel的数据导入到SQL的时候老是出现下面的错误:
配置选项 'show advanced options' 已从 1 更改为 1。请运行 RECONFIGURE 语句进行安装。
配置选项 'Ad Hoc Distributed Queries' 已从 1 更改为 1。请运行 RECONFIGURE 语句进行安装。
消息 7399,级别 16,状态 1,第 1 行
链接服务器 "(null)" 的 OLE DB 访问 ......
写SQL的比写.NET程序的体验上差一等,没有智能提示,需要记住关键字,函数或者不断地Copy表字段名,自定义函数,存储过程之类的。不过在
VS2010中,我们可以使用智能提示了,如下面几幅图所示:
在编辑器中, 输入 Shift + J
(提示: VS2010 开发工具中标的是 Ctrl +J 其实应该是 Shift + J )就可以自动打开这个智 ......
Student(S#,Sname,Sage,Ssex) 学生表
Course(C#,Cname,T#) 课程表
SC(S#,C#,score) 成绩表
Teacher(T#,Tname) 教师表
问题:
1、查询“001”课程比“002”课程成绩高的所有学生的学号;
select a.S# from (select s#,score from SC where C#='001') a,(select s#,score
fr ......
标准的 sql 的解析顺序为: (1).from 子句 组装来自不同数据源的数据
(2).where 子句 基于指定的条件对记录进行筛选
(3).group by 子句 将数据划分为多个分组
(4).使用聚合函数进行计算
(5).使用 having ......
Magento是在Zend Framework的基础上搭建而来,有两种方式可以从Magento的collection获得真正的SQL语句。
以 Mage::getResourceModel('reports/product_collection') 为例:
1
$collection=Mage::getResourceModel('reports/product_collection');
......