Adding Columns

R

RA

Hello Everyone,

I have been trying to solve this problem on my own for some time. I think I
am very close to accomplishing this task. Here is what I have

public void btnFillDG_Click(object sender, EventArgs e)
{
try
{

OleDbConnectionStringBuilder builder = new
OleDbConnectionStringBuilder();
builder.Provider = "Microsoft.ACE.OLEDB.12.0";
builder.DataSource = txtSelectExcelFile.Text;
builder["Extended Properties"] = "Excel 12.0;HDR=YES";

OleDbConnection ExcelDBConnect = new
OleDbConnection(builder.ConnectionString);

ExcelDBConnect.Open();
OleDbDataAdapter adpExcel = new OleDbDataAdapter("select *
from [Sheet1$]", ExcelDBConnect);
DataSet dsExcel = new DataSet();
adpExcel.Fill(dsExcel);
dataGridView1.DataSource = dsExcel.Tables[0];

DataColumn myDataColumn;
myDataColumn = new DataColumn();
myDataColumn.DataType = System.Type.GetType("System.String");
myDataColumn.ColumnName = "Test";
myDataColumn.ReadOnly = true;
myDataColumn.Unique = true;

dsExcel.Tables[0].Columns.Add(myDataColumn); //I NEED HELP
HERE?
dataGridView1.Refresh();

}

catch (StackOverflowException stack_ex2)
{
MessageBox.Show("(2007ExcelFile)Stack Overflowed!" + "\n" +
stack_ex2.Message);
}

catch (OleDbException ex_oledb2)
{
MessageBox.Show("An OleDb Error Thrown!" + "\n" +
ex_oledb2.Message);
}


}

Any advice as to how I add a column would be greatly appreciated.

Thank You,

RA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top