views:

294

answers:

2

I have problem while connecting to mysql database using "ADO.NET Driver for MySQL (Connector/NET)"

I got this exception The given key was not present in the dictionary.

Edit:

MySqlConnection con = new MySqlConnection("Server=localhost;Database=pgs_db;Uid=root;Pwd=;"); 
MySqlCommand com = new MySqlCommand(); 
com.CommandType = CommandType.StoredProcedure;
com.Connection = con;
com.CommandText = "getStudent";
con.Open();

MySqlDataReader dr =com.ExecuteReader(); 
GridView1.DataSource = dr; 
GridView1.DataBind();
con.Close();
A: 

Without seeing the code, I am guessing you are trying to access a configuration key that does not exist in your application config file.

Edit: After seeing the code sample, the problem is probably not with connecting to the DB.

I would say that in your GridView, you are binding to a field that is not returned by the DB query.

Oded
MySqlConnection con = new MySqlConnection("Server=localhost;Database=pgs_db;Uid=root;Pwd=;"); MySqlCommand com = new MySqlCommand(); com.CommandType = CommandType.StoredProcedure; com.Connection = con; com.CommandText = "getStudent"; con.Open(); MySqlDataReader dr =com.ExecuteReader(); GridView1.DataSource = dr; GridView1.DataBind(); con.Close();
mahmoud
i'm not using a configuration file , i have the connection string as plain text as above
mahmoud
Changed answer following comment. @mahmoud - when posting code examples, please add them to the question.
Oded
A: 

sorry i was using a worng connectionstring

this is a right one :

"server=localhost; user id=user; password=password; database=mydatabase; pooling=false;"

thnx Oded

mahmoud