Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

C# access a mysql database using ODBC have code running but not returning any records

Posted on 2011-09-23
6
420 Views
Last Modified: 2013-12-17
Hi Experts, easy on for you, i need to read a table from a mysql data base, have got the code going below, it runs does not throw up any errors but does not return any records, there are records there, but new are for me and am looking for help to get it going and some good reference material to read so i can underderstand  which ODBC connection comes in what order and what dataset needs what reference to what table ect.basicaly how to do it , but having a running code that works to play with.
any help would be appresiated, thanks

private System.Data.Odbc.OdbcConnection myConnection;
        private System.Data.Odbc.OdbcCommand cmd;
        private System.Data.Odbc.OdbcDataReader OdbcDR;
        private string connectionString;

        private void Readrec_Click(object sender, EventArgs e)
        {
           
            connectionString = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=" + txtIP.Text + ";PORT=" + txtPort.Text + ";DATABASE=" + txtDatabase.Text + ";UID=" + txtUsername.Text + ";PWD=" + txtPassword.Text + ";OPTION=3";
           // OdbcCon = new System.Data.Odbc.OdbcConnection(ConStr);
 
            OdbcConnection myConnection = new OdbcConnection(connectionString);
            DataSet ds = new DataSet("vtiger_account");
            OdbcDataAdapter da = new OdbcDataAdapter();
            OdbcCommand cmd = new OdbcCommand();
            cmd.CommandText = "SELECT vtiger_account.accountid, vtiger_account.account_no FROM vtiger_account ORDER BY vtiger_account.accountid DESC";
            da.SelectCommand = cmd;
            da.SelectCommand.Connection = myConnection;
            da.Fill(ds, "vtiger_account");
            DataTable tb = new DataTable("vtiger_account");
      //      DataTable tb = ds.Tables("accountid");

            foreach (DataRow row in tb.Rows)
            {

                string somename = (string)row["accountid"];
                //lstNames.Items.Add(somename);

            }  
0
Comment
Question by:sydneyguy
  • 3
  • 3
6 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 36590767
According to this page http://support.microsoft.com/kb/310988 , it looks like you're not opening the connection.
0
 

Author Comment

by:sydneyguy
ID: 36591523
connection seems to be opening ok as it does not throw up any errors it think its more to do with the loading of the data to the actual table, but could be wrong i have no workign code to say either way thus my question, but not sure how to check this
0
 

Author Comment

by:sydneyguy
ID: 36591955
its not the connection string thats workign fine
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 500 total points
ID: 36593142
Some where after the OdbcConnection is defined, you should have:

myConnection.Open()
0
 

Author Closing Comment

by:sydneyguy
ID: 36593221
thanks for the input have it all working now, understanding it a lot better now thanks for the help
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 36593241
You're welcome, glad you got it working.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question