VBA Vs C#

VBA Vs C#

We have a programe which was developed in C# used for invoices generations, now because it has no accounts receivable module, each time an invoice is generated it must be again captured manually in Ms Access application which has all the financial reporting modules.

Now my question is that , since C# is also a Microsoft product , then is there no way we can develop a code that can insert some of the similar field into Ms Access from C#. For example we have the following similar fields in both programes :

(1) Date
(2) Quantity Sold
(3) Price
(4) Total value

This way we will surely do away with manual
LVL 2
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.ScDirectorAsked:
Who is Participating?
 
mbizupConnect With a Mentor Commented:
Yes - You certainly can use C# to interface with an Access database.  The SQL statements would be identical.  The difference is that in Access your forms by default are bound.  In C#, your forms are unbound, and you need to connect to the database, and manipulate your data through code, similar to this (you should add try-catch code for error handling):
            /// 1. set up your connection string.  See www.connectionstrings.com for details.
            OleDbConnection conn = new OleDbConnection();
            conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\YourDatabasePath\YourDatabase.accdb";
            
            /// 2.  Set up your 'command'  (your action query),  Note the @ sign in the VALUES clause.  These are parameters that will be set later.
            OleDbCommand cmd = new OleDbCommand("INSERT into YourTableName (Date, QuantitySold, Price, TotalValue) Values(@Date, @QuantitySold, @Price, @TotalValue )");
            cmd.Connection = conn;

            /// 3.  Open the connection
            conn.Open();

            if (conn.State == ConnectionState.Open)
            {
                /// 4.  Set the parameter values
                cmd.Parameters.AddWithValue("@Date", YourDateField) ;
                cmd.Parameters.AddWithValue("@QuantitySold", YourQtyField);
                cmd.Parameters.AddWithValue("@Price", YourPriceField);
                cmd.Parameters.AddWithValue("@TotalValue, YourTotalValueField);

                    /// 5. Run the query
                    cmd.ExecuteNonQuery();

                    /// Clean things up
                    cmd.dispose;
                    cmd = nothing;
                    conn.Close();
                    conn= nothing;
            }
            else
            {
                /// Add handling for cases where the connection failed
            }

Open in new window

0
 
Michael PfisterConnect With a Mentor Commented:
Here is a longer article on how to connect C# and Access.
https://www.codeproject.com/Articles/1060352/Using-Microsoft-Access-Database-In-Csharp-ADO-NET

HTH
0
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.

All Courses

From novice to tech pro — start learning today.