任何人都可以帮我,我真的卡住了...... OLEDB连接 [英] Can anyone help me i really stuck ....OLEDB connection
本文介绍了任何人都可以帮我,我真的卡住了...... OLEDB连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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 !!!!!!!目前我在c#webform中使用多个下拉列表进行项目,如何实际使用oledb创建一个if else语句,允许我从多个下拉列表中搜索数据库。非常感谢
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
推荐答案
试试这个..
Try this..
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();
}
这篇关于任何人都可以帮我,我真的卡住了...... OLEDB连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文