I have a criteria where user uploads excel. So in that I want to check if column Is Replacement (Y/N)
has values as Y
then I want Replacement SAP ID
cannot be blank. If the column is blank then prompt a alert message. Below is the image for the same.
System.Data.OleDb.OleDbConnection connExcel = new System.Data.OleDb.OleDbConnection(conStr);
System.Data.OleDb.OleDbCommand cmdExcel = new System.Data.OleDb.OleDbCommand();
System.Data.OleDb.OleDbDataAdapter oda = new System.Data.OleDb.OleDbDataAdapter();
cmdExcel.Connection = connExcel;
connExcel.Open();
System.Data.DataTable dtExcelSchema = connExcel.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null);
System.Data.DataTable dtExcelColumnsTable = connExcel.GetSchema("Columns");
string SheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString().Replace(''', ' ').Trim(); //nadeem
cmdExcel.CommandText = "SELECT * From [" + SheetName + "]";
oda.SelectCommand = cmdExcel;
oda.Fill(dtExcelRows);
I take all columns in dtExcelRows
2
Answers
I think that It’s good to use your Business Exception and when the Replacement SAP ID is blank you should raise the Exception.
I just write some pseudo Code I’m not sure about reading data from a column.
And if you handle BadRequest exception in the front-end, you can prompt an alert message to the client.
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 :
??
Tip how to get a clearer view about what is happening
Basically at
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
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"
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