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 3
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.ScDirectorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Michael PfisterCommented:
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
mbizupCommented:
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

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