C#连接MySql问题
很简单的三句代码:
using MySql.Data.MySqlClient;//mysql-connector-net-5.1.2
MySqlConnection con = new MySqlConnection();
con.ConnectionString = "server=192.168.0.1; user id=www; password=123456; database=test; pooling=false; ";
con.Open();
运行时报错:
未将对象引用设置到对象的实例。
请问会是什么原因呢?
------解决方案--------------------得制定provider!
------解决方案--------------------dt = new DataTable();
conndb = new ConnDB( "localhost ", "autonomysprite ", "root ", "123456 ");
conndb.Open();
dt = conndb.Select(new string[] { "qid ", "uid ", "qtitle ", "qstatus ", "qdate "}, new string[] { "question " }, null, null, null);
this.dataGridView1.DataSource = dt;
我的代码运行正常
------解决方案--------------------用MySQLDriverCS.dll
------解决方案--------------------用MySQLDriverCS.dll
这个问题多多啊...
前段时间做个东东.把我搞死了.幸亏解决了.不过有一个问题,找不到资料去解决.估计是bug.
------解决方案--------------------Chech the ConnectStatus
Confirm the MqSql is running.
------解决方案--------------------MySQL ODBC Driver
------解决方案--------------------SqlConnection conn = new SqlConnection( "server=localhost;database=ExamDataBase;uid=sa;pwd=sa ");
conn.Open();
SqlCommand cmd = new SqlCommand( "ExamDataTable_Delete ", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add( "@id ", SqlDbType.Int);
cmd.Parameters[ "@id "].Value = Convert.ToInt16(ID.Text);
cmd.ExecuteNonQuery();
conn.Close();
------解决方案--------------------SqlConnection conn = new SqlConnection( "server=localhost;database=ExamDataBase;uid=sa;pwd=sa ");
conn.Open();
SqlDataAdapter da = new SqlDataAdapter( "ExamDataTable_Search ", conn);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
DataTable dt = new DataTable();
da.Fill(dt);