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 访问 ......
exec xp_cmdshell 'md E:\project'
--先判断数据库是否存在如果存在就删除
if exists(select * from sysdatabases where name='bbsDB')
drop database bbsDB
--创建数据库文件
create database bbsDB
--主数据库文件
on primary
(
name='bbsDB_data',--为主要数据库文件命名
filename='E:\proj ......
做毕业设计,最初考虑到方便性,在选择数据库时就用了Access(可移植性太强了),在测试时抛出了这样的错误:
System.Data.OleDb.OleDbException: INSERT INTO 语句的语法错误异常
遍寻网上高人,说法都各不一样,不过最后还是找到了问题所在:Access保留字!
因为在数据库设计时没有考虑到列名会与Access保留字重复,遂 ......
现象:
我的电脑--管理--服务--mssqlserver 服务 --启动
报错,1068,
或者,sqlserver 配置管理器中SqlServer 主服务启动 报错 提示说依存的服务或者组件没有启动,
原因:我是菜鸟,不太理解到底什么原因,但是找到了解决方法
解决方法:
SqlSe ......
Magento是在Zend Framework的基础上搭建而来,有两种方式可以从Magento的collection获得真正的SQL语句。
以 Mage::getResourceModel('reports/product_collection') 为例:
1
$collection=Mage::getResourceModel('reports/product_collection');
......