求一源代码 我是新手。。现在需要一个用c#且连接SQl2000的源代码!!谢谢指导!!请发到信箱[email protected] 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 System.Data.SqlClient.SqlConnection DB_Connect = null; System.Data.SqlClient.SqlCommand DB_Command = null; System.Data.SqlClient.SqlDataReader DB_Reader = null; string SQL_Command = string.Empty; string _DB_ConnStr = "workstation id=" + 服务器名称或IP + ";" + "packet size=4096;user id=" + 用户名称 + ";" + "data source=" + ODBC名称 + ";" + "persist security info=True;initial catalog=" + 数据库名称 + ";password=" + 密码 + ";Pooling=yes"; try { DB_Connect = new System.Data.SqlClient.SqlConnection(); DB_Command = new System.Data.SqlClient.SqlCommand(); if (DB_Connect.State == ConnectionState.Closed) { DB_Connect.ConnectionString = _DB_ConnStr; DB_Connect.Open(); } DB_Command.Connection = DB_Connect; SQL_Command = "SELECT name FROM sysobjects WHERE Lower(xtype)=\'u\'"; DB_Command.CommandText = SQL_Command; DB_Command.CommandType = CommandType.Text; DB_Command.Prepare(); DB_Reader = DB_Command.ExecuteReader(); while (DB_Reader.Read()) { if (!Convert.IsDBNull(DB_Reader["name"])) { //......; } } return true; } catch (SqlException ex) { return false; } finally { if (DB_Reader != null) { if (! DB_Reader.IsClosed) { DB_Reader.Close(); } } if (DB_Connect.State == ConnectionState.Open) { DB_Connect.Close(); DB_Connect.Dispose(); } DB_Connect = null; DB_Command = null; } SqlConnectionStringBuilder sb = new SqlConnectionStringBuilder();sb.UserID = "sa";sb.Password = "***********************";sb.DataSource = "(local)";sb.InitialCatalog = "master";SqlConnection conn = new SqlConnection( sb.ConnectionString ); 看来楼主联登陆CSDN都懒得蹬。 有没有大虾用C#开发过基于OpenGL的图形系统? 服务器和客户端通信问题 看见有人问工厂模式,再把以前发的大话设计模式翻出来供大家参考 visual studio2005加载OFFICE项目需要安装什么软件 分布式开发 editplus中正则表达式搜索日期问题 急!!!也问一个有关socket编程与信息监听的问题 DataGrid和一个CommandText的问题 ora-02041: 客户端数据库未开始一个事务处理 ADO EXCEL 插入问题 如何将一个字符串转化为16进制数,并且分别得到转换后的高8位和低8位? 如何动态还原类型
System.Data.SqlClient.SqlCommand DB_Command = null;
System.Data.SqlClient.SqlDataReader DB_Reader = null;
string SQL_Command = string.Empty;
string _DB_ConnStr = "workstation id=" + 服务器名称或IP + ";" + "packet size=4096;user id=" + 用户名称 + ";" + "data source=" + ODBC名称 + ";" + "persist security info=True;initial catalog=" + 数据库名称 + ";password=" + 密码 + ";Pooling=yes";
try
{
DB_Connect = new System.Data.SqlClient.SqlConnection();
DB_Command = new System.Data.SqlClient.SqlCommand();
if (DB_Connect.State == ConnectionState.Closed)
{
DB_Connect.ConnectionString = _DB_ConnStr;
DB_Connect.Open();
}
DB_Command.Connection = DB_Connect; SQL_Command = "SELECT name FROM sysobjects WHERE Lower(xtype)=\'u\'"; DB_Command.CommandText = SQL_Command;
DB_Command.CommandType = CommandType.Text;
DB_Command.Prepare();
DB_Reader = DB_Command.ExecuteReader(); while (DB_Reader.Read())
{
if (!Convert.IsDBNull(DB_Reader["name"]))
{
//......;
}
} return true;
}
catch (SqlException ex)
{
return false;
}
finally
{
if (DB_Reader != null)
{
if (! DB_Reader.IsClosed)
{
DB_Reader.Close();
}
}
if (DB_Connect.State == ConnectionState.Open)
{
DB_Connect.Close();
DB_Connect.Dispose();
}
DB_Connect = null;
DB_Command = null; }
sb.UserID = "sa";
sb.Password = "***********************";
sb.DataSource = "(local)";
sb.InitialCatalog = "master";SqlConnection conn = new SqlConnection( sb.ConnectionString );