?
Solved

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

Posted on 2011-09-23
6
Medium Priority
?
428 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
[X]
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
  • 3
  • 3
6 Comments
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 2000 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 84

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 2000 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 84

Expert Comment

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

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses

752 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