Results 1 to 2 of 2

Thread: Using C# to connect to MS Access files with SQL

  1. #1
    Join Date
    Mar 2011
    Posts
    2

    Using C# to connect to MS Access files with SQL

    Hey!

    I need to access a MS Access .mdb Database (exported by MS Project 2003) within my C# application.

    I tried to use the SQLClient class but couldn't find out which connectionstring allows me to access it. Is this even possible? I'd like to use the sqlcommands for this project.

    This is a code snippet of my SQLAccess class:


    class SQLAccess
    {
    public SQLAccess(string connectionstring, string commandstring) //e.g. commandstring = "SELECT name FROM Customers"
    {
    using (SqlConnection connection = new SqlConnection(connectionstring))
    {
    connection.Open();

    using (SqlCommand command = new SqlCommand(commandstring, connection))
    {
    using (SqlDataReader DataReader = command.ExecuteReader())
    {
    //...
    }
    }
    }
    }
    }

  2. #2
    Join Date
    Jan 2006
    Posts
    605

    Re: Using C# to connect to MS Access files with SQL

    I would simple create a method for premeters such as:

    public void setParameter(String paramAT, String paramTxt)
    Code:
        {
             OleDbCommand myCommand;
             DbParameter parameter = myCommand.CreateParameter();
             parameter.ParameterName = paramAT;
             parameter.Value = paramTxt;
             myCommand.Parameters.Add(parameter);
          }
    public int CreateDVD()
    Code:
     {
          try
    
           {
              string strSqldvd ="INSERT INTO DVD(title,locatie)VALUES(@title,@locate?)";
    
                myCommand = (OleDbCommand)dbconn.MyProvider.CreateCommand();          dbconn.MyConnection.Open();
              myCommand.Connection = dbconn.MyConnection;
              myCommand.CommandText = strSqldvd;
              setParameter("@title",M.Title );
              setParameter("@locate", M.Location);
    
          }
          catch (Exception)
          {
               throw new ArgumentException();
          }
           int count = myCommand.ExecuteNonQuery();
           dbconn.MyConnection.Close();
           return count;
      }

Similar Threads

  1. Read Access 2003 files with Access 2007
    By Kendal-J in forum Windows Software
    Replies: 2
    Last Post: 26-05-2010, 05:57 PM
  2. Replies: 7
    Last Post: 07-05-2010, 06:15 PM
  3. How to connect the VB6 with MS Access 2003?
    By Taylor D in forum Software Development
    Replies: 5
    Last Post: 14-01-2010, 10:12 AM
  4. How to connect the web form to Ms Access using ASP.NET?
    By VijayW in forum Software Development
    Replies: 2
    Last Post: 16-02-2009, 09:04 PM
  5. Files Access issue after putting in Access Rights
    By Simon Gronow in forum Windows Server Help
    Replies: 4
    Last Post: 30-01-2009, 07:23 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,305,038.99828 seconds with 16 queries