Prompt message if Excel column has some value in asp net c

0 votes

I have an option where users can submit Excel files. Therefore, I want to make sure that the Replacement SAP ID cannot be empty if the column Is Replacement (Y/N) has values of Y. When the column is empty, an alert message is displayed. The image for the same is seen below.

excel

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. 

Nov 24 in Others by Kithuzzz
• 20,660 points
27 views

1 answer to this question.

0 votes

I believe it is wise to use your business exception and to raise the exception when the replacement SAP ID is empty.

foreach(var item in dtExcelRows["ColumnName"]){
    if(string.IsEmptyOrNull(item){
           throw new HttpException((int)HttpStatusCode.BadRequest, "SAP ID is Empty.");
      }
}

I'm only writing some pseudo-Code. Regarding reading data from a column, I'm unsure.

Additionally, you can send a client alert message if you handle the BadRequest exception in the front end.

answered Nov 24 by narikkadan
• 37,660 points

Related Questions In Others

0 votes
0 answers

Format an Excel column (or cell) as Text in C#?

When I copy values from a data ...READ MORE

Oct 31 in Others by Kithuzzz
• 20,660 points
55 views
0 votes
1 answer

Excel - How can I get the average of cells where the value in one column is X and the value in another column is Y?

Use AVERAGEIFS ... =AVERAGEIFS(C2:C13,A2:A13,"Yellow Typ ...READ MORE

answered Nov 11 in Others by narikkadan
• 37,660 points
37 views
0 votes
1 answer

How to download SQL data in excel format using asp.net

Solution Download Open XML Download Close XML Library. import this Namespaces using System.IO; using System.Data; using ...READ MORE

answered Nov 14 in Others by narikkadan
• 37,660 points
51 views
0 votes
1 answer

How to find a value in an excel column by vba code Cells.Find

Just use: Dim Cell As Range Columns("B:B").Select Set cell = ...READ MORE

answered Nov 17 in Others by narikkadan
• 37,660 points
28 views
0 votes
1 answer

Deleting duplicate rows in Excel using Epplus

You need to re-think this… the while ...READ MORE

answered Feb 23 in Database by gaurav
• 22,040 points
296 views
0 votes
0 answers

Adding the CANONICAL tag to my page for SEO through code behind?

I am using ASP.NET with MasterPages. Thus ...READ MORE

Mar 3 in Digital Marketing by Kichu
• 19,040 points
292 views
0 votes
1 answer

Export DataTable to Excel File

Add Interop References. First we need to ...READ MORE

answered Jun 9 in JQuery by gaurav
• 22,040 points
112 views
0 votes
1 answer

How to create and download excel document using asp.net

First, download the Open XML Format SDK 2.0. It comes ...READ MORE

answered Oct 3 in Others by narikkadan
• 37,660 points
145 views
0 votes
1 answer

Excel - Make a graph that shows number of occurrences of each value in a column

There is probably a better way to ...READ MORE

answered Oct 21 in Others by narikkadan
• 37,660 points
75 views
0 votes
1 answer

Excel delete row if column contains value from to-remove-list

Given sheet 2: ColumnA ------- apple orange You can flag the rows ...READ MORE

answered Nov 6 in Others by narikkadan
• 37,660 points
56 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP