PDA

View Full Version : mySql connection?


mByte
11-05-2002, 10:36 AM
Does anybody know how to pull a record out of a database in C#?

I know how to access the database in php and in vp.net but I cannot get this code to work.

This code opens the database but I cannot pull information out with objDR.ExecuteReader().

anyhelp would be cool :)


MySqlConnection objConn;
MySqlCommand objCmd;
MySqlDataReader objDR;
string sqlQuery, objConnStr;
//int id;

objConnStr = "Data source=localhost;database=eq311;" +
"user id=sa;password=sa;command logging=false;";

objConn = new MySqlConnection(objConnStr);
objConn.Open();

sqlQuery = "Select * from items";

objCmd = new MySqlCommand();

objCmd.CommandType = CommandType.Text;
objCmd.CommandTimeout=30;
objCmd.CommandText=sqlQuery;
objCmd.Connection=objConn;

label1.Text = objConn.State.ToString();

mByte
11-05-2002, 12:01 PM
Nevermind figured out it was the file i was importing to talk to sqldb that was the problem.

I had to use a odbc connection but it works now :)