Click here to Skip to main content
15,899,935 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void BtnSubmit_Click(object sender, EventArgs e)
        {
           
                
                string ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\WebBasedData\WebBasedData\App_Data\MyDatabase.mdb;Persist Security Info=True";

                ///////////////////////////////////////////////////////////////////
                ////////////////SEARCH BY PRODUCT FAMILY///////////////////////////
                ///////////////////////////////////////////////////////////////////
                string strsql = "SELECT AssignmentID, Process, ProductFamily, PartNumber,station,Date,Time from TestFTQ WHERE ProductFamily LIKE '%" + DropDownList7.SelectedItem.Text +  "%';";
                //Create a OLEDBconnection to a database
                OleDbConnection con = new OleDbConnection(ConnectionString);
        
                //Create command to retrieve data from strsql              
                OleDbCommand cmd = new OleDbCommand(strsql, con);

                //open connection
                con.Open();

                OleDbDataReader Readproduct = cmd.ExecuteReader();

                if(( Readproduct.Read() == true))
                {

                //Create adapter for the testftq table
                OleDbDataAdapter oda = new OleDbDataAdapter(cmd);

                Readproduct.Close();

                //fill the dataset
                DataSet dset = new DataSet();
                oda.Fill(dset, " TestFTQ");

                //Create the data into the table in datagrid
                DataGrid1.DataSource = dset;
                DataGrid1.DataBind();

                }

                //Close connection
                con.Close();

hi !!!!!!! currently im doing a project with multiple dropdownlist in c# webform, how to actually use oledb to create a if else statement that can allow me to search in database from multiple dropdownlist. thank you so much
Posted
Updated 12-Dec-13 17:54pm
v2
Comments
Madhu Nair 12-Dec-13 23:59pm    
Do you want to search records in multiple databases?
acing wei 13-Dec-13 0:57am    
only one database but I need to select from multiple dropdown list like product family, process, ID... and when I click search button it will lookup to my database according to what I have selected from dropdownlist...
thank you so much

1 solution

Try this..
C#
protected void btnSearch_Click(object sender, EventArgs e)
    {
        OleDbCommand cmd = new OleDbCommand();
        cmd.Connection = conn;
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = "SELECT column1, column2, column3 from table WHERE column1 LIKE '%' + @Param1 +'%' and column2 LIKE '%' + @Param2 +'%'";
        cmd.Parameters.AddWithValue("@Param1", DropDownList7.SelectedItem.Text);
        cmd.Parameters.AddWithValue("@Param2", DropDownList8.SelectedItem.Text);
        conn.Open();
        cmd.ExecuteNonQuery();
        conn.Close();
    }
 
Share this answer
 
Comments
acing wei 13-Dec-13 1:21am    
hi creepz, but im not only select from one column , I need to look up to database in different column like I have productfamily,process and ID so that in the web whenI select from dropdownlist n I click search it will give me the correct data that im looking for..
thank you...I appreciate.
acing wei 16-Dec-13 3:36am    
Thank you its work, can I ask you more question next time??
creepz03 19-Dec-13 1:55am    
No problem dude.. as long as I'm available I'll be glad to help.
acing wei 19-Dec-13 3:22am    
Hi...I'm stuck again on the same project. I'm doing my final year project ,my project is about web-based data management system... I have many datatables in one database. i need to calculate it and show some data from those database , in the end plot another table in gridview to show the sum from all the datatables. do you have any suggestion what is the next move for this kind of project ? what im doing now is I filter out some data from a lot of datatables, is that the right way? i have been searching web for past 4 weeks...thanks in advanced....

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