14 Replies - 10538 Views - Last Post: 05 June 2010 - 08:22 AM Rate Topic: -----

#1 Mystic   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 49
  • Joined: 28-August 07

Transferring from Excel to MySQL

Posted 30 May 2010 - 01:52 PM

Hey people

I'm new to C# even though its quite similar to Java, which I used to use. Anyway, im trying to write a C# windows forms program to read values from excel files into an array list, which then be altered and then transferred to a MySQL Database. Now i have used the search function and google, and it seems that a very popular choice to read data is to treat the spreadsheet as database and then apply SQL commands. Problem with this is that normally a column would have a header name, however the excel files dont have this and to compound this matter, i have negligible experience with c# and this method of implementation. Furthermore, how would one make the program fill the array from values only in the A or B column? Another question is, once i manage to read values, how do i specify which worksheet with in the excel file must the program read from?

Here is the code i have so far, sorry for the messiness and ignore all the MySQL related code. The applicable code in this case is near the end, within button1.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.IO;
using System.Collections;
using MySql.Data.MySqlClient;
using Microsoft.Office.Core;
using Excel = Microsoft.Office.Interop.Excel;

namespace PriceChanger
{
    public partial class Form1 : Form
    {
        private OpenFileDialog openFileDialog1;

        string MyConString = "SERVER=localhost;" + "DATABASE=mydatabase;" + "UID=testuser;" + "PASSWORD=testpassword;";
        MySqlConnection connection = new MySqlConnection(MyConString);
        MySqlCommand command = connection.CreateCommand();
        MySqlDataReader Reader;


        ArrayList PriceList = new ArrayList();
        string Directory = "";

        int[] i = new int[9];

        string[] s = new string[8];

        public Form1()
        {
            InitializeComponent();

            
            command.CommandText = "select * from mycustomers";
            connection.Open();
            Reader = command.ExecuteReader();
            while (Reader.Read())
            {
                string thisrow = "";
                for (int i = 0; i < Reader.FieldCount; i++)
                    thisrow += Reader.GetValue(i).ToString() + ",";
                listBox1.Items.Add(thisrow);
            }
            connection.Close();

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            // ignore the following

           /* OpenFileDialog fdlg = new OpenFileDialog();
            fdlg.Title = "C# Corner Open File Dialog";
            fdlg.InitialDirectory = @"c:\";
            fdlg.Filter = "All files (*.*)|*.*|All files (*.*)|*.*";
            fdlg.FilterIndex = 2;
            fdlg.RestoreDirectory = true;
            
            if (fdlg.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = fdlg.FileName;
            }


            ArrayList k = new ArrayList();

            

            
            FolderBrowserDialog d = new FolderBrowserDialog();
            FileAttributes f = new FileAttributes();
            
            d.ShowDialog();
            FileInfo asq = new FileInfo("d");
            string dd = asq.FullName.ToString();
            //Directory = d.SelectedPath.ToString();
           // MessageBox.Show(Directory);
            String file = "";
            //file = System.IO.Directory.GetFiles(Directory);
            file = System.IO.Path.GetFullPath;
            MessageBox.Show(file);
             */
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
        Excel.Application myExcelApp;
        Excel.Workbooks myExcelWorkbooks;
        Excel.Workbook myExcelWorkbook;


        object misValue = System.Reflection.Missing.Value;


        myExcelApp = new Excel.ApplicationClass();
        myExcelApp.Visible = true;
        myExcelWorkbooks = myExcelApp.Workbooks;
        String fileName = "C:\Users\Mystic\Desktop\Pricelist.xls";                    

        Excel.Worksheet myExcelWorksheet = (Excel.Worksheet)myExcelWorkbook.ActiveSheet;
        
        String Position = "";
        String Workbook = "";

//due to the different excel files, applicable values are stored in different places and worksheets

        if (rdCorex = true)
        {
            Workbook = "Main Pricelist";
            Position = "B1";
        }
            if(rdFrontosa = true)
            {
                Workbook = "Main";
                Position = "A1";
            }
            if(rdRectron = true)
            {
                Workbook = "Main Pricelist";
                Position = "B1";
            }
        
        while(myExcelWorkbook.

        myExcelWorkbook = myExcelWorkbooks.Open(Workbook, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue);  

        PriceList.Add(myExcelWorksheet.get_Range(Position, misValue).Formula.ToString());

        myExcelWorksheetToChange.get_Range("C22", misValue).Formula = "New Value" \\ this changes the cell value in C2 to "New Value"
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }



    }
}



Here is a list of websites i visited as sources for my code.

http://social.msdn.m...4-9f5770fd9fd7/
http://www.dotnetspi...spx?ForumId=534



Thanks a lot

Is This A Good Question/Topic? 0
  • +

Replies To: Transferring from Excel to MySQL

#2 FlashM   User is offline

  • D.I.C Lover
  • member icon

Reputation: 383
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: Transferring from Excel to MySQL

Posted 30 May 2010 - 02:16 PM

It is possible to read excel file as database using SQL statements and I've done it before. But I wouldn't know how to treat the sheet if it has no column names. You could try something like SELECT A, B FROM mysheet or something similar.
Was This Post Helpful? 0
  • +
  • -

#3 Mystic   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 49
  • Joined: 28-August 07

Re: Transferring from Excel to MySQL

Posted 30 May 2010 - 11:54 PM

Well to put it bluntly, whats the exact code?
Was This Post Helpful? 0
  • +
  • -

#4 FlashM   User is offline

  • D.I.C Lover
  • member icon

Reputation: 383
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: Transferring from Excel to MySQL

Posted 30 May 2010 - 11:59 PM

I don't really have much time at the moment since I'm on my way to work. Take a look at this example:

http://www.davidhayd...05/26/2973.aspx

Hope this helps...
Was This Post Helpful? 0
  • +
  • -

#5 Mystic   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 49
  • Joined: 28-August 07

Re: Transferring from Excel to MySQL

Posted 31 May 2010 - 12:10 AM

ah i see, it does help except that it still requires table headers which i cant provide. having said that, it does explain that the code
""Excel 8.0;[u]HDR=YES[/u];"""
underlined means that there are headers. What if you said "No", would it then allow you to select from the column instead?

This post has been edited by Mystic: 31 May 2010 - 12:11 AM

Was This Post Helpful? 0
  • +
  • -

#6 FlashM   User is offline

  • D.I.C Lover
  • member icon

Reputation: 383
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: Transferring from Excel to MySQL

Posted 31 May 2010 - 12:14 AM

I suggest you try it and see if it works... Try selecting as previously mentioned like: SELECT A, B FROM [Sheet$];
Another solution would be to save this xls file as csv or some other text format and read it with StreamReader.
Was This Post Helpful? 0
  • +
  • -

#7 FlashM   User is offline

  • D.I.C Lover
  • member icon

Reputation: 383
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: Transferring from Excel to MySQL

Posted 31 May 2010 - 01:10 AM

OK, here's how it goes:

private OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Ales\Temp\Test.xls;Extended Properties=""Excel 8.0;HDR=No;IMEX=1"";");

private void button1_Click(object sender, EventArgs e)
{
    OleDbCommand cmd = new OleDbCommand("Select F1 from [List1$]", conn);

    conn.Open();

    using (OleDbDataReader reader = cmd.ExecuteReader())
    {
        while (reader.Read())
        {
            string fname = reader[0].ToString();

            Console.WriteLine("{0}", fname);
        }
    }

    conn.Close();
}




If the first row does not contain headers, the OLE DB provider automatically names the fields for you (where F1 would represent the first field, F2 would represent the second field, and so forth).

Hope this helps. If the post was helpful, click the '+' button to say thanks.

Keep up the good work.
Was This Post Helpful? 1
  • +
  • -

#8 Mystic   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 49
  • Joined: 28-August 07

Re: Transferring from Excel to MySQL

Posted 31 May 2010 - 01:17 PM

Thanks FlashM, just got a few minor probs now. In the conection string, you hard coded the source of the excel file. Now i tried to change that source to point to a string value i saved, since the excel file wont always have the same name or the same directory, but when i put the string variable in place of the hard coded directory with +variable+, i get an error. Also if i understand you correctly, F1 is the first field. If thats the case, then i assume F1 is the "header" for the first column, column A, and F2 is Column b and etc, etc. Then, how would i tell my program to start at cell A20, instead of A1, or B234?

Thanks a lot for your help, i do appreciate it.
Was This Post Helpful? 0
  • +
  • -

#9 FlashM   User is offline

  • D.I.C Lover
  • member icon

Reputation: 383
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: Transferring from Excel to MySQL

Posted 31 May 2010 - 02:00 PM

Could you post your connection string so I can see why you get an error when placing you variable instead of hard-coded file path? Yes, this is true, F1 is first column - column A, F2 in column B, etc. If you wanted to start reading at A20, then you should read all lines right from the beginning, but just do nothing with them, something like:

using (OleDbDataReader reader = cmd.ExecuteReader())
{
    int counter = 0;
    while (reader.Read())
    {
        counter++;
        if (counter < 20)
            continue;

        string fname = reader[0].ToString();

        Console.WriteLine("{0}", fname);
    }
}



For your connection string try the following:

private string file = @"C:\Ales\Temp\Test.xls";
private OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + file + @";Extended Properties=""Excel 8.0;HDR=No;IMEX=1"";");


Was This Post Helpful? 1
  • +
  • -

#10 Mystic   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 49
  • Joined: 28-August 07

Re: Transferring from Excel to MySQL

Posted 02 June 2010 - 02:39 AM

I was missing the "@" symbol, which seems to have caused the whole problem. What does the "@" do? Anyway now new problem popped up, C# throws me this error message "The 'Microsoft.Jet. OLEDB.4.0' provider is not registered on the local machine." which after a quick google search points out that my 64 bit machine cant run this. A solution seems to have me change my target build to the an x86 CPU, which i have done, but i still get that error. Im using windows 7 x64 professional with MS Visual Studio Pro 2008.
Was This Post Helpful? 0
  • +
  • -

#11 BigR1983   User is offline

  • D.I.C Head

Reputation: 57
  • View blog
  • Posts: 226
  • Joined: 12-April 10

Re: Transferring from Excel to MySQL

Posted 02 June 2010 - 11:12 AM

for strings, the @ allows you not have to escape the '\'

string = @"C:\Test"
string = "C:\\Test"


Was This Post Helpful? 0
  • +
  • -

#12 Mystic   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 49
  • Joined: 28-August 07

Re: Transferring from Excel to MySQL

Posted 03 June 2010 - 02:38 PM

Okay, here is the result of my programming so far.

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
using System.Data.OleDb;
using MySql.Data.MySqlClient;
using Microsoft.Office.Interop.Excel;
using Microsoft.Office.Core;

namespace Price_Calculator
{
    public partial class Form1 : Form
    {
        int temp = 0;
        ArrayList PList = new ArrayList();
        ArrayList Price = new ArrayList();
        int i = 0;
        ArrayList DB = new ArrayList();

        public Form1()
        {
            InitializeComponent();

           

           

            string DBConnect = "SERVER=10.0.0.1;" + "DATABASE=DB;" + "UID=testuser;" + "PASSWORD=testpassword;";
            MySqlConnection connection = new MySqlConnection(DBConnect);
            MySqlCommand command = connection.CreateCommand();
            MySqlDataReader Reader;
            //command.CommandText = "SELECT * FROM vm_product j WHERE columns = "product_sku"";
            connection.Open();
            //Reader = command.ExecuteReader();
            
            //while (Reader.Read())
            //{
            //    DB.Add(Reader.GetValue(i).ToString());
            //    listBoxShopDB.Items.Add(DB);
            //    i++;
            //}
            
        }

        private void Exit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Calculate_Click(object sender, EventArgs e)
        {
            PList.Clear();
            i = 0;

            OpenFileDialog file = new OpenFileDialog();

            file.ShowDialog();
            string FilePath = file.FileName.ToString();

            OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.                OLEDB.4.0;Data Source=" + FilePath + @";Extended Properties=""Excel 8.0;HDR=No;IMEX=1"";");

            if (rdCorex.Checked == true)
            {
                OleDbCommand cmd = new OleDbCommand("Select F1 from [$]", conn);
                conn.Open();

                using (OleDbDataReader XLreader = cmd.ExecuteReader())
                {
                    while (XLreader.Read())
                    {
                        PList.Add(XLreader.GetValue(i).ToString());
                        i++;
                    }
                }

               
            }
            if (rdFrontosa.Checked == true)
            {
                OleDbCommand cmd = new OleDbCommand("Select F1 from [Main$]", conn);
                OleDbCommand cmd2 = new OleDbCommand("Select F2 from [Main$]", conn);
                conn.Open();

                using (OleDbDataReader XLreader = cmd.ExecuteReader())
                {
                    while (XLreader.Read())
                    {
                        PList.Add(XLreader.GetValue(i).ToString());
                        i++;
                    }
                }

                using (OleDbDataReader XLreader = cmd.ExecuteReader())
                    {
                    while (XLreader.Read())
                        {
                        Price.Add(XLreader.GetValue(i).ToString());
                        i++;
                        }
                    }

                conn.Close();
            }
            if (rdRectron.Checked == true)
            {
                OleDbCommand cmd = new OleDbCommand("Select F2 from [Main Pricelist$]", conn);
                conn.Open();

                using (OleDbDataReader XLreader = cmd.ExecuteReader())
                {
                    while (XLreader.Read())
                    {
                        PList.Add(XLreader.GetValue(i).ToString());
                        i++;
                    }
                }
                conn.Close();
                MessageBox.Show("success 2 " + PList.Count);
                conn.Close();
            }

            bool check = false;

            TextWriter tw = new StreamWriter("temp.txt");
            TextWriter tw2 = new StreamWriter("Products not in Shop.txt");
            TextWriter tw3 = new StreamWriter("Products not in Datbase.txt");

            for (int u = 0; u < PList.Count; u++)
                {
                for (int j = 0; j < DB.Count; j++)
                    {
                    if (PList[u].Equals(DB[j]))
                        {
                        temp = int.Parse(Price[u].ToString()) * int.Parse(txtMarkUp.ToString());
                        Price[u] = temp.ToString();
                        check = true;
                        }
                    if (DB[u].Equals(PList[j]))
                        {
                            check = true;
                        }
                    }
                if (check == false)
                    {
                    tw2.WriteLine(PList[u]);
                    PList.RemoveAt(u);
                    Price.RemoveAt(u);
                    }
                }
            
            tw2.Close();
            PList.TrimToSize();
            Price.TrimToSize();

        }




    }









}



What i now want to know is, how do i compile this into a standalone .exe, assuming the relevant .net framework is installed on the target computer?


Thanks a lot for the help, have + rep'ed you.
Was This Post Helpful? 0
  • +
  • -

#13 Mystic   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 49
  • Joined: 28-August 07

Re: Transferring from Excel to MySQL

Posted 05 June 2010 - 05:51 AM

Ok well nevermind the last post. I now have one problem, as i have said in an earlier post, i now keep getting the error message which says "The 'Microsoft.Jet. OLEDB.4.0' provider is not registered on the local machine.". I have run my program on different operating systems now and made sure the Jet is installed on all the test machines, my program is targeting 32 bit operating system, but i still keep getting this error message and my program crashes.

My program.

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
using System.Data.OleDb;
using MySql.Data.MySqlClient;
using Microsoft.Office.Interop.Excel;
using Microsoft.Office.Core;

namespace Price_Calculator
{
    public partial class Form1 : Form
        {
        int temp = 0;
        ArrayList PList = new ArrayList();
        ArrayList PLPrice = new ArrayList();
        ArrayList DBSKU = new ArrayList();
        int i = 0;
        ArrayList DBPrimaryKey = new ArrayList();

        public Form1()
            {
            InitializeComponent();





            
            MySqlConnection connection = new MySqlConnection(DBConnect);
            MySqlCommand command = connection.CreateCommand();
            MySqlDataReader Reader;


            command.CommandText = "SELECT product_id, product_sku FROM jos_vm_product";
            command.CommandType = CommandType.Text;

            connection.Open();
            Reader = command.ExecuteReader();

            while (Reader.Read())
                {
                DBSKU.Add(Reader.GetValue(1).ToString());
                DBPrimaryKey.Add(Reader.GetValue(0).ToString());
                }


            }

        private void Exit_Click(object sender, EventArgs e)
            {
            this.Close();
            }

        private void Calculate_Click(object sender, EventArgs e)
            {
            PList.Clear();
            i = 0;

            OpenFileDialog file = new OpenFileDialog();

            file.ShowDialog();
            string FilePath = file.FileName.ToString();

            OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.                OLEDB.4.0;Data Source=" + FilePath + @";Extended Properties=""Excel 8.0;HDR=No;IMEX=1"";");

            if (rdCorex.Checked == true)
                {
                OleDbCommand cmd = new OleDbCommand("Select F1 from [$]", conn);
                OleDbCommand cmd2 = new OleDbCommand("Select F2 from [Main$]", conn);
                conn.Open();

                using (OleDbDataReader XLreader = cmd.ExecuteReader())
                    {
                    while (XLreader.Read())
                        {
                        PList.Add(XLreader.GetValue(i).ToString());
                        i++;
                        }
                    }

                i = 0;

                using (OleDbDataReader XLreader = cmd2.ExecuteReader())
                    {
                    while (XLreader.Read())
                        {
                        PList.Add(XLreader.GetValue(i).ToString());
                        i++;
                        }
                    }
                MessageBox.Show("corex success " + PList.Count);
                conn.Close();

                }
            if (rdFrontosa.Checked == true)
                {
                OleDbCommand cmd = new OleDbCommand("Select F1 from [Main$]", conn);
                OleDbCommand cmd2 = new OleDbCommand("Select F2 from [Main$]", conn);
                conn.Open();

                using (OleDbDataReader XLreader = cmd.ExecuteReader())
                    {
                    while (XLreader.Read())
                        {
                        PList.Add(XLreader.GetValue(i).ToString());
                        i++;
                        }
                    }

                i = 0;

                using (OleDbDataReader XLreader = cmd2.ExecuteReader())
                    {
                    while (XLreader.Read())
                        {
                        PLPrice.Add(XLreader.GetValue(i).ToString());
                        i++;
                        }
                    }
                MessageBox.Show("frontosa success " + PList.Count);
                conn.Close();
                }

            if (rdRectron.Checked == true)
                {
                OleDbCommand cmd = new OleDbCommand("Select F2 from [Main Pricelist$]", conn);
                OleDbCommand cmd2 = new OleDbCommand("Select F3 from [Main Pricelist$]", conn);
                conn.Open();

                using (OleDbDataReader XLreader = cmd.ExecuteReader())
                    {
                    while (XLreader.Read())
                        {
                        PList.Add(XLreader.GetValue(i).ToString());
                        i++;
                        }
                    }

                i = 0;

                using (OleDbDataReader XLreader = cmd2.ExecuteReader())
                    {
                    while (XLreader.Read())
                        {
                        PLPrice.Add(XLreader.GetValue(i).ToString());
                        i++;
                        }
                    }
                MessageBox.Show("rectron success " + PList.Count);
                conn.Close();
                }

            bool check = false;

            TextWriter tw = new StreamWriter("temp.txt");
            TextWriter tw2 = new StreamWriter("Products not in Shop.txt");
            TextWriter tw3 = new StreamWriter("Products not in Datbase.txt");

            for (int u = 0; u < PList.Count; u++)
                {
                for (int j = 0; j < DBSKU.Count; j++)
                    {
                    if (PList[u].Equals(DBSKU[j]))
                        {
                        temp = int.Parse(PLPrice[u].ToString()) * int.Parse(txtMarkUp.ToString());
                        PLPrice[u] = temp.ToString();
                        check = true;
                        }
                    if (DBSKU[u].Equals(PList[j]))
                        {
                        check = true;
                        }
                    }
                if (check == false)
                    {
                    tw2.WriteLine(PList[u]);
                    PList.RemoveAt(u);
                    PLPrice.RemoveAt(u);
                    }
                }

            tw2.Close();
            PList.TrimToSize();
            PLPrice.TrimToSize();


           
            MySqlConnection connection = new MySqlConnection(DBConnect);
            connection.Open();
            MySqlCommand InCommand = connection.CreateCommand();
            MySqlTransaction myTrans;

            myTrans = connection.BeginTransaction();
            // Must assign both transaction object and connection
            // to Command object for a pending local transaction
            InCommand.Connection = myConnection;
            InCommand.Transaction = myTrans;
            try
                {
                for (int z = 0; z < PLPrice.Count; z++)
                    {
                    InCommand.CommandText = "Update jos_vm_product_price SET product_price = " + PLPrice[z] + " WHERE product_id = " + DBPrimaryKey[z] + "";

                    InCommand.ExecuteNonQuery();
                    InTrans.Commit();
                    }

                }
            catch (Exception e)
                {
                try
                    {
                    myTrans.Rollback();
                    }
                catch (MySqlException ex)
                    {
                    if (myTrans.Connection != null)
                        {
                        Console.WriteLine("An exception of type " + ex.GetType() +
                                          " was encountered while attempting to roll back the transaction.");
                        }
                    }

                Console.WriteLine("An exception of type " + e.GetType() +
                                  " was encountered while updating the data.");
                }
            finally
                {
                connection.Close();
                }

            }



        }

}



How do i fix this?

This post has been edited by Mystic: 05 June 2010 - 08:23 AM

Was This Post Helpful? 0
  • +
  • -

#14 elbielefeld   User is offline

  • D.I.C Head

Reputation: 70
  • View blog
  • Posts: 217
  • Joined: 18-May 10

Re: Transferring from Excel to MySQL

Posted 05 June 2010 - 07:44 AM

Hi,

//What is that space?
OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.                OLEDB.4.0;Data Source=" + FilePath + @";Extended Properties=""Excel 8.0;HDR=No;IMEX=1"";");


Was This Post Helpful? 0
  • +
  • -

#15 Mystic   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 49
  • Joined: 28-August 07

Re: Transferring from Excel to MySQL

Posted 05 June 2010 - 08:22 AM

Thanks for the reply, i fixed my problem by using the ACE drivers instead. Ok new problem. When i try to update my tables, i an error message saying

Quote

"Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index"
. here is the relevant part of the program:

string DBConnect = "SERVER=blank;" + "DATABASE=blank;" + "UID=user;" + "PASSWORD=blank;";
            MySqlConnection connection = new MySqlConnection(DBConnect);
            connection.Open();
            MySqlCommand InCommand = connection.CreateCommand();
            MySqlTransaction myTrans;

            MessageBox.Show("Sucess");


            myTrans = connection.BeginTransaction();
            // Must assign both transaction object and connection
            // to Command object for a pending local transaction
            InCommand.Connection = connection;
            InCommand.Transaction = myTrans;
            try
                {
                for (int z = 0; z < PLPrice.Count; z++)
                    {
// this is where the error message kicks in.
                    InCommand.CommandText = "Update jos_vm_product_price SET product_price = " + PLPrice[z] + " WHERE product_id = " + DBPrimaryKey[z] + "";

                    
                    
                    }
                     myTrans.Commit();

                }

            finally
                {
                connection.Close();
                }

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1