i wanted to upload the columns of a table from Excel, so I uploaded the table in a Dataset and then checked the column names and inserted in database. you can get an idea from the below code
for (int i = 0; i < dsUpload.Tables[0].Columns.Count; i++)
{
if (dsUpload.Tables[0].Columns[i].ColumnName.ToString() != "")
{
// Assigning ColumnName
objExcelUpload.ColumnName = dsUpload.Tables[0].Columns[i].ColumnName.ToString().Replace("'", "''").Replace("<", "<").Replace(">", ">").Trim();
if (!objExcelUpload.ifColumnNameExist("insert"))
{
if (objExcelUpload.ColumnName != "")
{
objExcelUpload.insertColumns();
}
}
else
{
ErrorLabel.Text = "The column name already exists. Please select a different name.";
return;
}
}
}
Here ds Upload is a dataset name
and the code useful for you is
objExcelUpload.ColumnName = dsUpload.Tables[0].Columns[i].ColumnName.ToString()
which is checked in a loop of all the available columns
for (int i = 0; i < dsUpload.Tables[0].Columns.Count; i++)
Let me know if you need any clarification :-)
OleDbConnection
– Martin Smith