顶!我也碰到同样的问题
data source是指数据库名
data source是指数据库名
解决方案 »
- 无奈了,全过程
- 求一个分页查询SQL语句
- 请教一个SendKeys.SendWait("{Prtsc}")的问题
- 大家来分享侦听源码!!
- 用ScaleTransform和TranslateTransform应用画布后画出来的字是反的!
- 在线等啊 ultratree或treeview的编辑问题
- 关于C#中的virtual、new和override
- 如何获取文件创建时候的时间戳
- 问问要写个语音通讯的软件需要 掌握哪些 技术?散分
- C#如何安装?
- C#中怎么 将从数据库中选出数值型数据用取整后显示出来?(sqlserver库,把原来的字段/1024/1024后取整,怎么办?)
- 关于google APIs,最近是怎么了,
http://community.csdn.net/Expert/topic/3121/3121364.xml?temp=7.302493E-02
using System.Data.SqlClient;public class DataReaderSql
{
public static int Main(string[] args)
{
string source =“data source=(local);initial catalog=Northwind;integrated security=SSPI;”; string select = "SELECT ContactName,CompanyName FROM Customers" ; SqlConnection conn = new SqlConnection ( source ) ; try
{
using ( conn )
{
conn.Open ( ) ; SqlCommand cmd = new SqlCommand ( select , conn ) ; using ( SqlDataReader aReader = cmd.ExecuteReader ( ) )
{
while ( aReader.Read ( ) )
Console.WriteLine ( "'{0}' from {1}" , aReader.GetString(0) , aReader.GetString ( 1 ) ) ; aReader.Close ( ) ;
} conn.Close ( ) ;
}
}
catch ( Exception e )
{
Console.WriteLine ( e ) ;
Console.WriteLine ( ) ;
Console.WriteLine ( "Chances are your database does not have a user" ) ;
Console.WriteLine ( "called QSUser, or you do not have the NetSDK database installed." ) ;
} return 0;
}
}
其中datasource后表示为默认本地服务器
用这个"Data Source=server;Database=mydb;User ID=username;Password=pwd;Command Logging=false" 也不行
应该是这样的
MySQLDriverCS.MySQLConnection conn = new MySQLDriverCS.MySQLConnection (new MySQLDriverCS.MySQLConnectionString("127.0.0.1",database,use id,password).AsString);
例如
MySQLDriverCS.MySQLConnection conn = new MySQLDriverCS.MySQLConnection (new MySQLDriverCS.MySQLConnectionString("localhost","test","root","").AsString);
这样就可以连上数据库