如果cat_id&显示主页Sub_CAT_ID不存在.. [英] Display the homepage if cat_id & Sub_CAT_ID doesn't exists..

查看:45
本文介绍了如果cat_id&显示主页Sub_CAT_ID不存在..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void Page_Load(object sender,EventArgs e)

{

int j = Convert.ToInt32(Request.QueryString [Cat_Id]);

int i = Convert.ToInt32(Request.QueryString [Sub_Cat_Id]);





SqlConnection con = new SqlConnection(@Data Source = .\SQLEXPRESS; AttachDbFilename = D:\ site \SamsungClassifieds\App_Data\Dorknozzle.mdf; Integrated Security = True; User Instance = True);



con.Open();



SqlDataAdapter cmd = new SqlDataAdapter(SELECT AD_ID,AD_TITLE,AD_DESC,AD_IMG, AD_PRICE,AD_NO,SUB_CAT_DESC,CAT_DESC,SELLER_NAME,SELLER_MOB_NO,SELLER_EMAIL_ID,SELLER_DEP,SELLER_FLOOR,DATE来自AD_DETAIL_V WHERE(DATE> = {fn CURDATE()})和BUY_SELL_ID ='1'和DELETED_AD ='0'AND SUB_CAT_ID = + i +AND CAT_ID =+ j,con);

DataSet ds = new DataSet();

cmd.Fill(ds);

gvImages.DataSource = ds;

gvImages.DataBind();



}





i和j是结果页面的cat_id和Sub_cat_ID,如果cat_ID和Sub_Cat_do不存在,我希望它重定向到主页。



示例 - http:// localhost:50476 / SamsungClassifieds / Results.aspx?Cat_Id = 4& Sub_Cat_Id = 10000

它将重定向到主页。

protected void Page_Load(object sender, EventArgs e)
{
int j = Convert.ToInt32(Request.QueryString["Cat_Id"]);
int i = Convert.ToInt32(Request.QueryString["Sub_Cat_Id"]);


SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\site\SamsungClassifieds\App_Data\Dorknozzle.mdf;Integrated Security=True;User Instance=True");

con.Open();

SqlDataAdapter cmd = new SqlDataAdapter("SELECT AD_ID,AD_TITLE, AD_DESC, AD_IMG, AD_PRICE, AD_NO, SUB_CAT_DESC, CAT_DESC, SELLER_NAME, SELLER_MOB_NO, SELLER_EMAIL_ID, SELLER_DEP, SELLER_FLOOR,DATE FROM AD_DETAIL_V WHERE (DATE >= { fn CURDATE() }) and BUY_SELL_ID='1' and DELETED_AD = '0' AND SUB_CAT_ID= " + i + "AND CAT_ID =" + j, con);
DataSet ds = new DataSet();
cmd.Fill(ds);
gvImages.DataSource = ds;
gvImages.DataBind();

}


i and j are the cat_id & Sub_cat_ID of the result page i want it to redirect to home page if the cat_ID & Sub_Cat_doesn't exists.

Example - http://localhost:50476/SamsungClassifieds/Results.aspx?Cat_Id=4&Sub_Cat_Id=10000
it will redirect to homepage.

推荐答案

您必须首先检查DataSet中表的计数。如果它是零重定向到主页。



You have to check first the count of the tables in your DataSet. If it is zero redirect to the homepage.

DataSet ds = new DataSet();
cmd.Fill(ds);

int count = ds.Tables[0].Rows.Count;

if (count == 0)
   Response.Redirect("HomePage.aspx");

gvImages.DataSource = ds;
gvImages.DataBind();





谢谢 hypermellow [ ^ ]!



我希望它可以提供帮助!如果出现问题,请告诉我!



Thank you hypermellow[^]!

I hope it could help! Let me know if something is wrong!


此代码将重定向到HomePage无论我们将在Resultpage的Url中写什么。即字母,数字,删除整个网址后?......







protected void Page_Load(对象发送者,EventArgs e)

{



int iCatID;

int iSubCatID;

string j = Request.QueryString [Cat_Id];

string i = Request.QueryString [Sub_Cat_Id];



SqlConnection con = new SqlConnection(@Data Source = .\ SQLEXPRESS; AttachDbFilename = D:\ site \SamsungClassifieds\App_Data \Dorknozzle.mdf; Integrated Security = True; User Instance = True);

con.Open();

if(i == null && j == null)

{

Response.Redirect(HomePage.aspx);

}

else

if((int.TryParse(i.ToString(),out iCatID))&&(int.TryParse(j.ToString(), out iSubCatID)))

{

//这里你的数据库检索.....

SqlDataAdapter cmd = new SqlDataAdapter(SELECT AD_ID,AD_TITLE,AD_DESC,AD_IMG,AD_PRICE,AD_NO,SUB_CAT_DESC,CAT_DESC,SELLER_NAME,SELLER_MOB_NO,SELLER_EMAIL_ID,SELLER_DEP,SELLER_FLOOR,DATE来自AD_DETAIL_V WHERE(DATE> = {fn CURDATE()})和BUY_SELL_ID ='1'和DELE TED_AD ='0'AND SUB_CAT_ID =+ iCatID.ToString()+AND CAT_ID =+ iSubCatID.ToString(),con);

DataSet ds = new DataSet();

cmd.Fill(ds);

int count = ds.Tables [0] .Rows.Count;

if(count == 0)



Response.Redirect(HomePage.aspx);



gvImages.DataSource = ds;

gvImages.DataBind();

}

else

{//处理参数类型错误(即 - 显示消息或重定向用户)

Response.Redirect(HomePage.aspx);

}

}
This Code will redirect to HomePage Whatever we will write in the Url of ResultPage. i.e Alphabet,Numbers,Remove whole Url after ?......



protected void Page_Load(object sender, EventArgs e)
{

int iCatID;
int iSubCatID;
string j = Request.QueryString["Cat_Id"];
string i = Request.QueryString["Sub_Cat_Id"];

SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\site\SamsungClassifieds\App_Data\Dorknozzle.mdf;Integrated Security=True;User Instance=True");
con.Open();
if (i == null && j == null)
{
Response.Redirect("HomePage.aspx");
}
else
if((int.TryParse(i.ToString(), out iCatID))&&(int.TryParse(j.ToString(), out iSubCatID)))
{
//Do your DB retrieval here .....
SqlDataAdapter cmd = new SqlDataAdapter("SELECT AD_ID,AD_TITLE, AD_DESC, AD_IMG, AD_PRICE, AD_NO, SUB_CAT_DESC, CAT_DESC, SELLER_NAME, SELLER_MOB_NO, SELLER_EMAIL_ID, SELLER_DEP, SELLER_FLOOR,DATE FROM AD_DETAIL_V WHERE (DATE >= { fn CURDATE() }) and BUY_SELL_ID='1' and DELETED_AD = '0' AND SUB_CAT_ID= " + iCatID.ToString() + "AND CAT_ID =" + iSubCatID.ToString(), con);
DataSet ds = new DataSet();
cmd.Fill(ds);
int count = ds.Tables[0].Rows.Count;
if (count == 0)

Response.Redirect("HomePage.aspx");

gvImages.DataSource = ds;
gvImages.DataBind();
}
else
{ //Handle the parameter type error (i.e. - display a message or redirect user)
Response.Redirect("HomePage.aspx");
}
}


如何显示id和它在树视图中的子ID

这是我的代码在c#和ms访问数据库中它没有显示所有它



private void button2_Click(对象发送者,EventArgs e)

{

l:



尝试

{



con = new OleDbConnection(cs);

con.Open();

//销售。 ReferenceID = Customer.CustomerID和

cmd = new OleDbCommand(SELECT * from Sales where CustomerID ='+ textBox22.Text +'order by CustomerID ASC,con);

OleDbDataAdapter myDA = new OleDbDataAdapter(cmd);

DataTable rdr = new DataTable();

myDA.Fill(rdr);



for(int i = 0;我< rdr.Rows.Count; i ++)

{

TreeNode node = new TreeNode(rdr.Rows [i] [CustomerNameSales]。ToString());

node.Nodes.Add(rdr.Rows [i] [ReferenceID]。ToString());

node.Nodes.Add(rdr.Rows [i] [CustomerID]。ToString ());

node.Nodes.Add(rdr.Rows [i] [Rank]。ToString());

node.Nodes.Add(rdr .Rows [i] [checkcol]。ToString());

treeView1.Nodes.Add(node);

}





con.Close();



}

catch(异常) ex)

{

MessageBox.Show(ex.Message,Error,MessageBoxButtons.OK,MessageBoxIcon.Error);

}



t ry

{



con = new OleDbConnection(cs);

con.Open();

String ct102000 =从Sales中选择CustomerID,其中ReferenceID ='+ textBox22.Text +';

cmd = new OleDbCommand(ct102000,con);

rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);





if((rdr.Read()== true ))

{



textBox21.Text =(rdr [CustomerID]。ToString());

textBox22.Text = textBox21.Text;



if(textBox22.Text!= null)

{

goto l;



}



goto l;

}



con.Close();

}

catch(Exception ex)

{

MessageBox.Show(ex.Message,Error,MessageBoxButtons.OK,MessageBoxIcon.Error);

}







}

给我一个解决方案
hOW TO display a data of id and its sub ids in treeview
this is my code in c# and ms access data base it not displaying all of it

private void button2_Click(object sender, EventArgs e)
{
l:

try
{

con = new OleDbConnection(cs);
con.Open();
//Sales.ReferenceID = Customer.CustomerID and
cmd = new OleDbCommand("SELECT * from Sales where CustomerID='" + textBox22.Text + "' order by CustomerID ASC ", con);
OleDbDataAdapter myDA = new OleDbDataAdapter(cmd);
DataTable rdr = new DataTable();
myDA.Fill(rdr);

for (int i = 0; i < rdr.Rows.Count; i++)
{
TreeNode node = new TreeNode(rdr.Rows[i]["CustomerNameSales"].ToString());
node.Nodes.Add(rdr.Rows[i]["ReferenceID"].ToString());
node.Nodes.Add(rdr.Rows[i]["CustomerID"].ToString());
node.Nodes.Add(rdr.Rows[i]["Rank"].ToString());
node.Nodes.Add(rdr.Rows[i]["checkcol"].ToString());
treeView1.Nodes.Add(node);
}


con.Close();

}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

try
{

con = new OleDbConnection(cs);
con.Open();
String ct102000 = "SELECT CustomerID from Sales where ReferenceID = '" + textBox22.Text + "'";
cmd = new OleDbCommand(ct102000, con);
rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);


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

textBox21.Text = (rdr["CustomerID"].ToString());
textBox22.Text = textBox21.Text;

if (textBox22.Text != null)
{
goto l;

}

goto l;
}

con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}



}
give me a solution


这篇关于如果cat_id&amp;显示主页Sub_CAT_ID不存在..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆