Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I want to send a confirmation email to user after checking if a container is one way or not (by comparing input text with a range of container numbers in an excel sheet). I basically want to show an alert in case a container # matches with excel sheet value. Else, send confirmation msg. How do I achieve this? right now,the way I have coded, it sends out confirmation email regardless. Here is my code:
C#
public void Btn_SubmitClick(Object sender, EventArgs E) 
            {
                string path = @"C:\TEMP\OneWayContainers.xls";
                string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;";
                OleDbConnection objConn = new OleDbConnection(connStr);
                objConn.Open();
                OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM MyRange", objConn);
                OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
                objAdapter1.SelectCommand = objCmdSelect;
                DataSet objDataset1 = new DataSet();
                objAdapter1.Fill(objDataset1, "XLData");
                string strExcelContainerInfo="";
                strContainerInfoText= _SendContainerInfo.Value;
                
               if(objDataset1.Tables[0].Rows.Count>0)
               {
                
                    for (int i = 0; i < objDataset1.Tables[0].Rows.Count; i++)
                        {
                            strExcelContainerInfo = Convert.ToString(objDataset1.Tables[0].Rows[i]["OneWayContainers"].ToString());
                          
                            if (strContainerInfoText.Contains(strExcelContainerInfo) )
                            {                        
                                ClientScript.RegisterClientScriptBlock(this.GetType(), "alert","alert('Container: "+strExcelContainerInfo+" is a one-way container.');window.location='Redirect.aspx';", true); 
                                break;                          
                            } 
                            else
                            { 
                                continue;
                            }
                            
                         }                        
                         
                           if ( (string)Session["Fullname"] == null ||(string)Session["Fullname"] == "")
                            {   reCheckSession();
                                return;
                            }
                            else
                            {   Logic to send  confirmation email 
                            }
                 }
     }
Posted
Comments
j snooze 14-Sep-15 17:53pm    
Without giving you the code(that makes your job too easy where's the fun in that :))Try googling System.Net.Mail, that should help you find it.
Rajesh_1980 15-Sep-15 9:39am    
Thanks for the reply J snooze. I am not looking for the code to send out email.I already have it in place and it is just not shown here. I am asking for a resolution to my problem where the email gets sent irrespective of whether the entered container number is one-way or not (after showing the alert in case it is a one-way).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900