Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Datasource datatable as column headers for drop down

$
0
0

Hallo

Hope somebody can assist.

I got various pricelist I'm importing into SQL, but the column headers need to be matched with the correct columns in SQL.

So i create the import code and getting the tables into a datatable, I want to set the various dropdown boxes for the operator to select the correct Column with the correct field in SQL. I cannot find a way to create the list in a dropdown to display the headers only.

       private void btnImport_Click(object sender, EventArgs e)
        {
            progresstimer.Start();
            progresstimer.Enabled = true;
            if ((FilePath != "") && (this.txtSheetName.TextLength > 0)) //Get the sheet names
            {

                string ConnPath = ConToExcel(FilePath);
                OleDbConnection conn = new OleDbConnection(ConnPath);

                try
                {
                    string str = "";
                    str = "Select * from [" + this.txtSheetName.Text + "$]";
                    OleDbDataAdapter da = new OleDbDataAdapter(str,conn);

                    DataTable dt = new DataTable();


                    da.Fill(dt);
                    da.Fill(temdt);
                    dgExcelData.DataSource = dt;
                    this.txtImportRectotal.Text = dt.Rows.Count.ToString();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
            else
            {
                MessageBox.Show("Please make sure you selected File Name and Sheet Name");
            }
            progresstimer.Stop();
            progressbarTop.Value = 0;

        }

       private void cmdPartNr_MouseClick(object sender, MouseEventArgs e)
        {
            this.cmdPartNr.DataSource = temdt.Columns[0].ToString();
        }
    }


labjac


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>