search ข้อมูล ค้นหาข้อมูลระหว่างวันที่และ ดรอปดาน์วลิส
ขอเรียงก่อน เด๋วมาตอบค่ะ
Code (C#)
void ShowData()
{
string sql = "Select productsupplier.*,productsupplierdt.* From productsupplier,productsupplierdt where productsupplier.Id(+) = productsupplierdt.ProductSupplierId Group By ProductSupplierId";
string strdate = Csql.Convert_dateCalendar(txtStartDate.Text);
string enddate = Csql.Convert_dateCalendar(txtendDate.Text);
if ((txtStartDate.Text != string.Empty) && (txtendDate.Text != string.Empty) && (ddlProduct.SelectedValue != "--กรุณาเลือก--"))
{
dtP = Csql.SELECT_All("productsupplier where (DateBuy between '" + strdate + "'AND'" + enddate + "') AND SupplierId='" + ddlProduct.SelectedValue + "'");
}
else if ((txtStartDate.Text != string.Empty) && (txtendDate.Text != string.Empty))
{
dtP = Csql.SELECT_All("productsupplier WHERE DateBuy between '" + strdate + "'AND'" + enddate + "'");
}
else if ((txtStartDate.Text == string.Empty) && (txtendDate.Text == string.Empty))
{
dtP = Csql.SELECT_All("productsupplier");
}
else
{
string str = "<script language='javascript'>alert('กรุณาใส่ช่วงวันที่');window.focus ();</script>";
Page.RegisterStartupScript("onclick", str);
return;
}
if (dtP.Rows.Count > 0)
{
GV1.DataSource = dtP;
GV1.DataBind();
}
else
{
//DataTable dt = new DataTable();
//dt.Columns.Add(new DataColumn("Id", typeof(int)));
//DataRow dr = dt.NewRow();
//dt.Rows.Add(dr);
//GV1.DataSource = dt;
GV1.DataSource = null;
GV1.DataBind();
}
}
protected void GV1_RowCreated(object sender, GridViewRowEventArgs e )
{
string strdate = Csql.Convert_dateCalendar(txtStartDate.Text);
string enddate = Csql.Convert_dateCalendar(txtendDate.Text);
if (e.Row.RowType == DataControlRowType.DataRow)
{
HyperLink data1 = (HyperLink)e.Row.FindControl("data1");
HyperLink data2 = (HyperLink)e.Row.FindControl("data2");
HyperLink data3 = (HyperLink)e.Row.FindControl("data3");
HyperLink data4 = (HyperLink)e.Row.FindControl("data4");
string sql = "Select productsupplier.*,productsupplierdt.* From productsupplier,productsupplierdt where (productsupplier.DateBuy between '" + strdate + "' AND '" + enddate + "') AND productsupplier.Id = productsupplierdt.ProductSupplierId Group By ProductSupplierId";
DataTable dt = Csql.ExecuteReader(sql);
//Response.Write(sql);
//Response.End();
if (dt.Rows.Count > 0)
{
data1.Text = dt.Rows[e.Row.DataItemIndex]["ReceiveCode"].ToString();
data1.NavigateUrl = "Buy.aspx?actions=Edit&uid=" + dt.Rows[e.Row.DataItemIndex]["SupplierId"].ToString();
data2.Text = dt.Rows[0]["DateBuy"].ToString();
data3.Text = dt.Rows[0]["TotalPrice"].ToString();
data4.Text = dt.Rows[0]["Status"].ToString();
}
}
runid = (e.Row.DataItemIndex + 1) + ".";
}
Date :
2010-08-05 23:16:00
By :
njnight
Code (C#)
string strdate = Csql.Convert_dateCalendar(txtStartDate.Text + " 00:00:00");
string enddate = Csql.Convert_dateCalendar(txtendDate.Text + " 23:59:00");
ตอบถูกประเด็นหรือป่าวคะ ^_^
Date :
2010-08-05 23:20:24
By :
njnight
อันนี้ที่เราใช้อยู่อ่ะค่ะ เราไม่ค่อยใช้ Between เท่าใหร่
Code (C#)
string Qstr_select = " SELECT * FROM issue_table ";
Qstr_select += " where ";
if (txtStartDate.Text.Trim() != "" && txtEndDate.Text.Trim() != "")
{
Qstr_select += " recorddate >='@Date_Begin' and recorddate <='@Date_End' ";
Qstr_select = Qstr_select.Replace("@Date_Begin", txtStartDate.Text + " 00:00:00");
Qstr_select = Qstr_select.Replace("@Date_End", txtEndDate.Text + " 23:59:00");
}
Date :
2010-08-05 23:23:04
By :
njnight
ขอบคุณทุก ๆ คำตอบคร้าบบบบทำได้แว้ว เย้ ๆ
Date :
2010-08-06 00:42:43
By :
party
Load balance : Server 01