|
|
|
กด ปุ่ม search data gridview ไม่โชว์ค่ะ และไม่แสดง error ช่วยด้วยค่ะ T-T |
|
|
|
|
|
|
|
Code (C#)
protected void searchData()
{
string sql = "SELECT DISTINCT "
+ "A.B_TYPE, A.B_YEAR, A.B_DIST, B1.GD_NAME AS Division, B2.GD_NAME AS Brand, B3.GD_NAME AS Gram, A.B_SOURCE, A.B_MAT_TYPE, A.B_DEST_cntry,"
+ "A.b_ton1, A.b_baht1, A.b_ton2, A.b_baht2, A.b_ton3, A.b_baht3, A.b_ton4, A.b_baht4, A.b_ton5, A.b_baht5, A.b_ton6, A.b_baht6, A.b_ton7, A.b_baht7, A.b_ton8,"
+ "A.b_baht8, A.b_ton9, A.b_baht9, A.b_ton10, A.b_baht10, A.b_ton11, A.b_baht11, A.b_ton12, A.b_baht12"
+ " FROM MIS_BUDGET_AA3 AS A INNER JOIN "
+ "[MIS_GEN_DETAILS ] AS B1 ON B1.GD_NO = A.B_DIV AND B1.GD_TYPE = 'div' INNER JOIN "
+ "[MIS_GEN_DETAILS ] AS B2 ON B2.GD_NO = A.B_GROUP3 AND B2.GD_TYPE = 'MGRP3' INNER JOIN "
+ "[MIS_GEN_DETAILS ] AS B3 ON B3.GD_NO = A.B_GROUP2 AND B3.GD_TYPE = 'MGRP2' "
+ "WHERE B_TYPE=' " + ddlBudgetS.SelectedValue + "' AND B_YEAR='" + ddlYearS.SelectedValue
+ "' AND B1.GD_NAME =' " + ddlDivisionS.SelectedValue + "' AND B_SOURCE =' " + ddlsourceS.SelectedValue
+ "' AND B3.GD_NAME =' " + ddlgramS.SelectedValue + "' AND B2.GD_NAME =' " + ddlbrandS.SelectedValue
+ "' AND B_MAT_TYPE =' " + ddlMS.SelectedValue+"'";
SqlConnection con = new SqlConnection(con_string);
SqlCommand cmd = new SqlCommand(sql,con);
try {
if (ddlBudgetS.SelectedValue!="")
{ cmd.Parameters.AddWithValue("@B_TYPE",ddlBudgetS.SelectedValue);
}
if (ddlbrandS.SelectedValue!= "")
{
cmd.Parameters.AddWithValue("@B_GROUP3",ddlbrandS.SelectedValue);
}
if (ddlgramS.SelectedValue!= "")
{
cmd.Parameters.AddWithValue("@B_GROUP2",ddlgramS.SelectedValue);
}
if (ddlMS.SelectedValue!= "")
{
cmd.Parameters.AddWithValue("@B_MAT_TYPE",ddlMS.SelectedValue);
}
if (ddlsourceS.SelectedValue!= "")
{
cmd.Parameters.AddWithValue("@B_SOURCE", ddlsourceS.SelectedValue);
}
if(ddlYearS.SelectedValue!=""){
cmd.Parameters.AddWithValue("@B_YEAR",ddlYearS.SelectedValue);
}
if(ddlDivisionS.SelectedValue!=""){
cmd.Parameters.AddWithValue("@B_DIV",ddlDivisionS.SelectedValue);
}
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();
SqlDataAdapter da = new SqlDataAdapter(sql,con);
DataSet ds = new DataSet();
da.Fill(ds, "Data");
int count = ds.Tables["Data"].Rows.Count;
if (count > 0)
{
gvSearch.DataSource = ds.Tables["Data"];
gvSearch.DataBind();
}
}catch (Exception ex) { lblError.Text = ex.ToString(); }
finally { con.Close(); }
}
protected void btnsearch_Click(object sender, EventArgs e)
{
this.searchData();
}
Tag : .NET, Web (ASP.NET), C#
|
|
|
|
|
|
Date :
2011-04-23 17:47:45 |
By :
mumeaw |
View :
1132 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไม่โชว์น่าจะเป็นที่ข้อมูลที่ Query ไม่มีครับ
|
|
|
|
|
Date :
2011-04-23 22:38:35 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (C#)
protected void searchData()
{
string sql = "SELECT DISTINCT "
+ "A.B_TYPE, A.B_YEAR, A.B_DIST, B1.GD_NAME AS Division, B2.GD_NAME AS Brand, B3.GD_NAME AS Gram, A.B_SOURCE, A.B_MAT_TYPE, A.B_DEST_cntry,"
+ "A.b_ton1, A.b_baht1, A.b_ton2, A.b_baht2, A.b_ton3, A.b_baht3, A.b_ton4, A.b_baht4, A.b_ton5, A.b_baht5, A.b_ton6, A.b_baht6, A.b_ton7, A.b_baht7, A.b_ton8,"
+ "A.b_baht8, A.b_ton9, A.b_baht9, A.b_ton10, A.b_baht10, A.b_ton11, A.b_baht11, A.b_ton12, A.b_baht12"
+ " FROM MIS_BUDGET_AA3 AS A INNER JOIN "
+ "[MIS_GEN_DETAILS ] AS B1 ON B1.GD_NO = A.B_DIV AND B1.GD_TYPE = 'div' INNER JOIN "
+ "[MIS_GEN_DETAILS ] AS B2 ON B2.GD_NO = A.B_GROUP3 AND B2.GD_TYPE = 'MGRP3' INNER JOIN "
+ "[MIS_GEN_DETAILS ] AS B3 ON B3.GD_NO = A.B_GROUP2 AND B3.GD_TYPE = 'MGRP2' "
+ "WHERE B_TYPE=' " + ddlBudgetS.SelectedValue + "' AND B_YEAR='" + ddlYearS.SelectedValue
+ "' AND B1.GD_NAME =' " + ddlDivisionS.SelectedValue + "' AND B_SOURCE =' " + ddlsourceS.SelectedValue
+ "' AND B3.GD_NAME =' " + ddlgramS.SelectedValue + "' AND B2.GD_NAME =' " + ddlbrandS.SelectedValue
+ "' AND B_MAT_TYPE =' " + ddlMS.SelectedValue+"'";
SqlConnection con = new SqlConnection(con_string);
SqlCommand cmd = new SqlCommand(sql,con);
try {
con.Open();
SqlDataAdapter da = new SqlDataAdapter(sql,con);
DataSet ds = new DataSet();
da.Fill(ds, "Data");
gvSearch.DataSource = ds.Tables["Data"];
gvSearch.DataBind();
con.Close();
}catch (Exception ex)
{
lblError.Text = ex.ToString();
}
}
protected void btnsearch_Click(object sender, EventArgs e)
{
this.searchData();
}
ลองแบบนี้จะได้มั้ยครับ
|
|
|
|
|
Date :
2011-04-25 10:22:47 |
By :
mi16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไม่ออกค่ะ อยากทราบว่าต้องการตั้งค่า ให้ griadview ในหน้า design หรือ ป่าวค่ะ ขอบคุณค่ะ
|
|
|
|
|
Date :
2011-04-26 16:47:24 |
By :
mumeaw |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|