|
|
|
รบกวนขอโค๊ด search จากฐานข้อมูลหน่อยครับ เอาเป็น c# นะครับ |
|
|
|
|
|
|
|
search อะไร ประมาณไหน
ใช้ DBMS ตัวไหน MySql, Access, SQL Server, Oracle
อันนี้ ใช้ SQL Server 2005
เป็นการ search แล้วโชว์ข้อมูล ลงใน กริดวิว
protected void btnSearch_Click(object sender, EventArgs e)
{
string strConn2 = "Data Source=MIXAR-PC;Initial Catalog=StockProductInfo;Integrated Security=True";
SqlConnection Conn2 = new SqlConnection(strConn2);
if (Conn2.State == ConnectionState.Open)
{
Conn2.Close();
}
Conn2.ConnectionString = strConn2;
Conn2.Open();
string sqlCustSearch;
sqlCustSearch = "SELECT DISTINCT masCustomer.Cust_ID AS CustID, ";
sqlCustSearch += "masCustomer.Cust_FName AS Firstname, ";
sqlCustSearch += "masCustomer.Cust_LName AS Lastname, ";
sqlCustSearch += "masCustomer.Cust_Tel AS Telephone, ";
sqlCustSearch += "tabCustomerType.CustType_Name AS Type ";
sqlCustSearch += "FROM masCustomer, tabCustomerType ";
sqlCustSearch += "WHERE (masCustomer.CustType_ID = tabCustomerType.CustType_ID)";
if (ddlCustomerType.SelectedItem.Value != "Select...")
{
sqlCustSearch += "AND (tabCustomerType.CustType_Name = '" + ddlCustomerType.SelectedItem.Text + "')";
}
if (txtCustID.Text != "")
{
sqlCustSearch += "AND (masCustomer.Cust_ID LIKE '" + txtCustID.Text + "%')";
}
if (txtFirstname.Text != "")
{
sqlCustSearch += "AND (masCustomer.Cust_FName LIKE '" + txtFirstname.Text + "%')";
}
if (txtLastname.Text != "")
{
sqlCustSearch += "AND (masCustomer.Cust_LName LIKE '" + txtLastname.Text + "%')";
}
if (txtTelephone.Text != "")
{
sqlCustSearch += "AND (masCustomer.Cust_Tel LIKE '" + txtTelephone.Text + "%')";
}
SqlDataAdapter da3 = new SqlDataAdapter(sqlCustSearch, Conn2);
da3.Fill(ds, "Customers");
dgvCustResult.DataSource = ds.Tables["Customers"];
dgvCustResult.DataBind();
if (dgvCustResult.Rows.Count <= 0)
{
Response.Write("<script type='text/javascript'>alert('Search not found!!');</script>");
ddlCustomerType.SelectedValue = "Select...";
txtCustID.Text = "";
txtFirstname.Text = "";
txtLastname.Text = "";
txtTelephone.Text = "";
}
else
{
dgvCustResult.Visible = true;
}
Conn2.Close();
}
|
|
|
|
|
Date :
2009-02-10 12:23:27 |
By :
mixarstudio |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุนมากครับ
ของผมใช้ access ครับ
การ search รหัสพนักงานจากฐานข้อมูลครับ
|
|
|
|
|
Date :
2009-02-11 00:23:34 |
By :
devil |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แต้ ก่ะนิ
|
|
|
|
|
Date :
2011-02-07 22:32:44 |
By :
SubaRu |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|