Index
Example answer is almost at the end - just above references section. Hope it helps you.
Unclear scope
It is hard to grasp exact tech stack You are referring to. Are you limited to OleDb? or can you use any nuget package? What are the restrictions / technical base for "promt a alert message" ? webforms? ASP.NET 2.0? I mean, is it an AJAX control toolkit alert or a simple
type Javascript ? maybe one within jQuery which should only open after the page ( if rendered ) is rendered :
jQuery(document).ready(function() {window.alert("message");})
??
Tip how to get a clearer view about what is happening
Basically at
cmdExcel.CommandText = "SELECT * From [" + SheetName + "]";
oda.SelectCommand = cmdExcel;
oda.Fill(dtExcelRows);
it seems for me that you actually fill the dataset with whole sheet data, not only the names from the first row
If you have Visual Studio, write something trivial just after the oda.Fill line, like
String t= "";
place a breakpoint on this trivial line (or any line with code just after that Fill one
then press F5.
After IISExpress is launched, in the page go to the upload scenario where this code will run, and then when debugger pauses on the debug point you just set,
select word dtExcelRows
then right click
Add to Watch
lower you will see Watch toolbar there near the dtExcelRows is magnifiying glass.
That is DataSet visualizer. Click on that and you will see what was filled actually inside the dtExcelRows object
Now you can figure out what exactly you need.
Answer to Your question
Unfortunately unless I know more exact details about approximate technical limits (version of ASP.NET or other technology, it will be long to try to write all the possible variants how this could be implemented.)
Therefore I will limit myself to a "pseudocode"
// i think you could alse refer to an index
//(dtExcelRows as DataSet).Tables[0].Rows[0].ToString();
DataSet dtExcelRowsShoulBeDataSet = (dtExcelRows as DataSet);
if (dtExcelRowsShoulBeDataSet != null) {
if (dtExcelRowsShoulBeDataSet.Tables.Length > 0) {
int numberOfColumns = dtExcelRowsShoulBeDataSet.Tables[0].Columns.Count;
String columnNameDoYouNeedItOrNumberIsEnoug_Question_Column = "";
String columnNameDoYouNeedItOrNumberIsEnoug_REPLACEMENTSAPID_Column = "";
foreach (DataColumn column in dtExcelRowsShoulBeDataSet.Tables[0].Columns) {
if (row [column]
.ToString()
.Trim()
.StartsWith("Is Replacement")) {
columnNameDoYouNeedItOrNumberIsEnoug_Question_Column =
column.ColumnName;
} else if (row [column]
.ToString()
.Trim()
.StartsWith("Replacement SAP")) {
columnNameDoYouNeedItOrNumberIsEnoug_REPLACEMENTSAPID_Column =
column.ColumnName;
}
}
//now you know the column names, so can use them alike dictionary indexes
for (int i = 1; i < dtExcelRowsShoulBeDataSet.Tables[0].Rows.Count; i++) {
if (row [columnNameDoYouNeedItOrNumberIsEnoug_Question_Column]
.ToString()
.Trim()
.ToUpper() != "Y" &&
row [columnNameDoYouNeedItOrNumberIsEnoug_Question_Column]
.ToString()
.Trim()
.ToUpper() != "N") {
// later .net versions you can use IsNullOrWhiteSpace method here
if (String.IsNullOrEmpty(
row
[columnNameDoYouNeedItOrNumberIsEnoug_REPLACEMENTSAPID_Column]
.ToString()
.Trim())) {
// if AJAX then registerscript, addstartupscript etc..
Response.Write(
"<scipt type=\"text/javascript\">window.alert(\"hey, you forgot to specify the Replacement SAP ID at Excel row Nr " +
(i) + " !\")</script>");
Response.End();
}
}
}
}
}
References
Microsoft .NET C# documentation pages.
Just add the viewFallbackFrom parameter (or simply edit the view= parameter from current default 6 to your older tech stack version. So you can currently do in any Microsoft documentation site to see what is avaliable for your version_
https://learn.microsoft.com/en-us/dotnet/api/system.data.datacolumn?view=net-6.0&viewFallbackFrom=net-3.0