Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

Syntax issues...

Why is this not working???  Im trying to convert this: http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21253647.html (VB.NET) to this...
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        private System.Data.Odbc.OdbcConnection mconnCurrent;
        private const string mstrServerName = "localhost";
        private const string mstrUsername = "root";
        private const string mstrPassword = "wd006451";

        static void Main(string[] args)
        {
            string sqlSelect;
            System.Data.Odbc.OdbcDataAdapter com;
            System.Data.Odbc.OdbcCommand queryCom;
            System.Data.DataSet ds;
            string strConn;
            string strDBName;

            strDBName = "test";
            strConn = "DRIVER={MySQL ODBC 3.51 Driver}" +
                         ";SERVER=" + mstrServerName +
                         ";DATABASE=" + strDBName +
                         ";UID=" + mstrUsername +
                         ";PWD=" + mstrPassword +
                         ";OPTION=3";
            this.mconnCurrent = new System.Data.Odbc.OdbcConnection(strConn);
            this.mconnCurrent.Open();

        }
    }
}
0
clear100-com
Asked:
clear100-com
  • 2
1 Solution
 
vbguestCommented:
Could you be more specific on what your problem is? What do you mean by "not working"?
0
 
YurichCommented:
1. well, as a starter, you have to add a reference to your "MySQL ODBC 3.51 Driver", which is Microsoft.Data.Odbc.dll file if I remember correct.

2. Where did you find this line: using System.Collections.Generic; ? and why do you need it?

3. Next one, there is no namespace System.Data.Odbc

you have to use Microsoft.Data.Odbc

and even better, just specify a namespace

using Microsoft.Data.Odbc;

and then create a Odbc components directly: OdbcConnection myConnection = ... or OdbcDataAdpater da = ...

4. If you want ot initialize your connection in the Main function, everything should be move inside the Main function as well, I mean all that stuff:

        OdbcConnection mconnCurrent;
        string mstrServerName = "localhost";
        string mstrUsername = "root";
        string mstrPassword = "wd006451";

5. So, after all your code should be like that:

using System;
using System.Collections; //.Generic;
using System.Text;
using Microsoft.Data.Odbc;


namespace ConsoleApplication1
{
      class Program
      {
            static void Main(string[] args)
            {
                                               OdbcConnection mconnCurrent;
                  string mstrServerName = "localhost";
                                                string mstrUsername = "root";
                                                string mstrPassword = "wd006451";


                  string sqlSelect;
                  
                  OdbcDataAdapter com;
                  OdbcCommand queryCom;
                  
                  System.Data.DataSet ds;
                  
                  string strConn;
                  string strDBName;

                  strDBName = "test";
                  strConn = "DRIVER={MySQL ODBC 3.51 Driver}" +
                        ";SERVER=" + mstrServerName +
                        ";DATABASE=" + strDBName +
                        ";UID=" + mstrUsername +
                        ";PWD=" + mstrPassword +
                        ";OPTION=3";
                  
                  mconnCurrent = new OdbcConnection(strConn);
                  mconnCurrent.Open();

            }
      }
}


regards,
mik


0
 
YurichCommented:
that's a link to download the odbc driver:

http://dev.mysql.com/downloads/connector/odbc/3.51.html
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now