vs2005如何连入SQL Server2005的数据库 c#

[复制链接]
查看11 | 回复1 | 2009-11-13 00:51:55 | 显示全部楼层 |阅读模式
sqlcon = "Data Source=.或其他机器;Initial Catalog=你要连接的数据库;Persist Security Info=True;User ID=数据库用户名;Password=数据库密码";使用数据库必用的两个命名空间using System.Data;
using System.Data.Sqlclient;
回复

使用道具 举报

千问 | 2009-11-13 00:51:55 | 显示全部楼层
string sqlcon = "Data Source=.或其他机器;Initial Catalog=你要连接的数据库;Persist Security Info=True;User ID=sa;Password=sa";;
string sql = "select * from 你要查询的表名";
SqlConnection con = new SqlConnection(sqlcon);//连接对象
//打开连接
con.Open();
SqlCommand cmd = new SqlCommand(sql,con);
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行