-
August 31st, 2015, 09:50 AM
#1
Compare input value with stored dataset values.
Hi all, I am new to C# programming. I am able to compare the entered value of an input field with stored values in a dataset. However, I am having trouble doing the same with multiple input fields. Here is my code with single input field. Please advise how to go about the same with multiple input fields. Thanks in advance for any help.
Code:
protected void Submit_click(object sender, EventArgs e)
{
// Create connection string variable. Modify the "Data Source"
// parameter as appropriate for your environment.
string path = @"C:\TEMP\ExcelSearchWebApp\OneWayContainers.xlsx";
string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;";
// Create connection object by using the preceding connection string.
OleDbConnection objConn = new OleDbConnection(connStr);
// Open connection with the database.
objConn.Open();
// The code to follow uses a SQL SELECT command to display the data from the worksheet.
// Create new OleDbCommand to return data from worksheet.
OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM MyRange", objConn);
// Create new OleDbDataAdapter that is used to build a DataSet
// based on the preceding SQL SELECT statement.
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
// Pass the Select command to the adapter.
objAdapter1.SelectCommand = objCmdSelect;
// Create new DataSet to hold information from the worksheet.
DataSet objDataset1 = new DataSet();
// Fill the DataSet with the information from the worksheet.
objAdapter1.Fill(objDataset1, "XLData");
string strExcelContainerInfo;
string strContainerInfoText= Convert.ToString(txtCntrInfo.Text).ToUpper();
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()); //fetch Name clm from db
if (strContainerInfoText == strExcelContainerInfo )
{
ScriptManager.RegisterStartupScript(this, this.GetType(),"alert","alert('OneWayContainer');window.location ='RedirectPage.aspx';",true);
}
else
{
//Submit form logic;
}
}
}
// Clean up objects.
objConn.Close();
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|