以下是效果,就是如果数据库id字段==null,那么就跳转到GsjjInsert.aspx,否则不等于null就跳转到GsjjSelect.aspx
但问题是如果id没数据的话就报错啊。怎么办啊?protected void Page_Load(object sender, EventArgs e)
{
string sqlselect = "select * from q_gsjj";
DataSet ds = db.GetDS(sqlselect);
if (ds.Tables[0].Rows[0]["id"].ToString() == null)//在位置 0 处没有任何行。
{
Response.Redirect("GsjjInsert.aspx");
}
else
{
Response.Redirect("GsjjSelect.aspx");
}
}
但问题是如果id没数据的话就报错啊。怎么办啊?protected void Page_Load(object sender, EventArgs e)
{
string sqlselect = "select * from q_gsjj";
DataSet ds = db.GetDS(sqlselect);
if (ds.Tables[0].Rows[0]["id"].ToString() == null)//在位置 0 处没有任何行。
{
Response.Redirect("GsjjInsert.aspx");
}
else
{
Response.Redirect("GsjjSelect.aspx");
}
}
解决方案 »
- datagridview 使用RemoveAt(0) 占用CPU资源高的问题
- c# 当窗体出现时,如何让Textbox中的内容不处于全选状态??
- 请高手指点,初学ajax,ie提示出错:'Sys.WebForms.PageRequestManagerServerErrorException:...404
- 多个表实现Treeview的问题 有经验的进来看看 在线等
- 为什么用Application.StartupPath就会出错?
- 这个正则表达式错在哪里?
- 请教:这种类型的软件用什么来开发好呢?(附图)
- 在listbox中如何获得选中行的特定列的信息
- C#(Win Form)中DataGrid怎样刷新?
- 问一个问题,高手提供一下思路,谢谢
- OWC10的问题,请解释一下.....
- 在winform中,大家都用什么显示数据列表?
加个判断
if(ds.table[0].Rows.Count>0)
{
///
}
table.Rows[rowIndex][columnIndex].ToString() 或者Convert.To指定类型(table.Rows[rowIndex][columnIndex])
if(ds.Tables.Rows.Count>0 && ds.Tables[0].Rows.Count>0)
{
if (ds.Tables[0].Rows[0]["id"].ToString() == null)//在位置 0 处没有任何行。
{
Response.Redirect("GsjjInsert.aspx");
}
else
{
Response.Redirect("GsjjSelect.aspx");
}
}
{
string sqlselect = "select * from q_gsjj";
DataSet ds = db.GetDS(sqlselect);
if(ds.Tables[0].Rows.Count>0)
{
if (ds.Tables[0].Rows[0]["id"].ToString().length>0)
{
Response.Redirect("GsjjSelect.aspx");
}
else
{
Response.Redirect("GsjjInsert.aspx");
}
}
else
{
Response.Write("<script>alert('No Data!')</script>");
}
}首先,要考虑此时数据库中是否存在数据;其次,才是id值是否存在
而且我有一个地方不太明白,因为你是无条件查询,可能会存在第一行的id为空,后面的id不为空,你不能仅因为第一行的id就判断它是进入哪个页面吧?或者你可以如下做法: protected void Page_Load(object sender, EventArgs e)
{
string sqlselect = "select * from q_gsjj where id is not null";
DataSet ds = db.GetDS(sqlselect);
if(ds.Tables[0].Rows.Count>0)
{
Response.Redirect("GsjjSelect.aspx");
}
else
{
Response.Redirect("GsjjInsert.aspx");
}
}
ds.Tables[0].Rows[0]["id"] 这个是在读第一行啊肯定不行啊加个
if(ds.Tables[0].Rows.Count>0)
就行了