Convert this simple Java prog to C# : I'm trying to learn.

Hello experts,
I've recently become very interested in C#.
I purchased a few books on the subject and plan to learn it.

Anyhow, what's a better way to learn then by example and pracitce?

I would be very greatful if someone could convert the following Java program to a C# program.

*******CODE STARTS HERE*************

package woj.mysql;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
 * @author Wojciech Dunski
 *
 */
public class reloadMaster {
      
      private ResultSet rs;
      private static Connection conn;
    private Statement stat;
   
    public reloadMaster(){
          try{
                conn = getConnection();
          }
          catch (SQLException e)
        {  
           e.printStackTrace();
        }
          catch(IOException ioe){
                ioe.printStackTrace();
          }
    }
   
    public static Connection getConnection()
          throws SQLException, IOException
          {
          System.setProperty("jdbc.drivers", "com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/inventory";
        String username = "root";
        String password = "sunrise";
        return DriverManager.getConnection(url, username, password);
          }
   
    public void executeQueries(){
          boolean done;
          try{             
                String query = "DELETE masterInventory from masterInventory;";
                Statement st = conn.createStatement();
            done = st.execute(query);
           
             Statement stt = conn.createStatement();
             String reload = "LOAD DATA local INFILE 'C:/masterin.csv' " +
                         "INTO TABLE masterinventory FIELDS TERMINATED BY ',' " +
                         "OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\\n';";
             done = stt.execute(reload);
           
              }
              catch (SQLException e)
            {  
               e.printStackTrace();
            }
    }
      /**
       * @param args
       */
      public static void main(String[] args) {
            reloadMaster reload = new reloadMaster();
            reload.executeQueries();
      }
}

***** CODE ENDS HERE ********

I would love it if someone could convert this to C# and point out some of the major differences.
C# seems very interesting : )

Thanks very much!
Wojciech Dunski.
LVL 2
wdunskiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mmarksburyCommented:
Better yet, go to http://www.asp.net/vwd/starterkits.aspx?tabIndex=4&tabId=46 and download some of the starter kits.  This is how I learned, and it was amazing at how easy it is to pick up.  I've just made the move from C# to Java due to a work move, and all I can say is you'll be much happier with C#.
0
findsukeshCommented:
Hi Wojciech,

The corresponding C# code would for accessing MYSQL Database would like as below

------------------------------------------------------
public class reloadMaster
      {
     
            private static OdbcConnection conn;
            
            public reloadMaster()
            {
                  try
                  {
                        conn = getConnection();
                  }
                  catch (OdbcException odbce)
                  {  
                        Console.WriteLine(odbce.StackTrace);
                  }
                  catch(Exception e)
                  {
                        Console.WriteLine(e.StackTrace);
                  }
            }
            public static OdbcConnection getConnection()
            {
                  String strconn = "Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=inventory;uid=root;pwd=sunrise;option=3";
                  return DriverManager.getConnection(strconn);
                  /*
                   * In the DriverManager you will have to write code like below
                   * to create the connection object
                   *
                   * OdbcConnection odbcconn = new OdbcConnection(strconn);
                   *  
                   */
            }

            public void executeQueries()
            {
                  try
                  {            
                        String query = "DELETE masterInventory from masterInventory;";
                        OdbcCommand odbccmd = conn.CreateCommand();
                        odbccmd.CommandText = query;
                        odbccmd.ExecuteNonQuery();
           
                        OdbcCommand odbccmd2 = conn.CreateCommand();
                        String reload = "LOAD DATA local INFILE 'C:/masterin.csv' " +
                              "INTO TABLE masterinventory FIELDS TERMINATED BY ',' " +
                              "OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\\n';";
                        odbccmd2.CommandText = reload;
                        odbccmd2.ExecuteNonQuery();
           
                  }
                  catch (OdbcException e)
                  {  
                        Console.WriteLine(e.StackTrace);
                  }
            }
            public static void main(String[] args)
            {
                  reloadMaster reload = new reloadMaster();
                  reload.executeQueries();
            }

    }
-------------------------------------------------------

But as suggested by other experts, It is better to go through the documentation, starter kits and other samples available at microsoft msdn site http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/netfxanchor.asp

Thanks and Regards,
Sukesh
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wdunskiAuthor Commented:
Sounds good.
One last question:
Which namespace do I need to use for the OdbcConnection?
I treid System.Data.Obdc but that doesnt seem to work.

Thanks.
0
findsukeshCommented:
Hi Wojciech,

You have to use the namespace System.Data.Odbc. Please check the spelling you have used.

Try and use Visual Studio intellisense to avoid such spelling mistakes.

Regards,
Sukesh.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.