我是用Datagrid绑定,超级连接列“数据添加”数据库一共有两个表一个是品牌表,一个是详细数据表!详细数据表的主键是外键!所以数据都是根据这个外键编号,来的!
我像求一条判断语句 如果这条数据在数据库中已经存在那样就重新定向到出错的页面。源码如下:private void Page_Load(object sender, System.EventArgs e)
{
par_id.Text = Request.QueryString["cheID"].ToString();if(!IsPostBack)
{
SqlConnection con = DataCon.AutoCon();
con.Open();SqlCommand cma = new SqlCommand("select * from cnat_nf",con);
SqlDataReader sda = cma.ExecuteReader();
this.par_lhb.DataSource = sda;
this.par_lhb.DataTextField = "cnat_nf";
this.par_lhb.DataValueField = "cnat_id";
this.par_lhb.DataBind();
this.par_lhb.Items.Insert(0,new ListItem("—请选推出年份—","-1"));
sda.Close(); 
con.Close();
}
private void par_tj_Click(object sender, System.EventArgs e)
{
int lhb = int.MinValue;SqlConnection con = DataCon.AutoCon();
con.Open();SqlCommand cmd = new SqlCommand("cheParameter_ADD",con);
cmd.CommandType = CommandType.StoredProcedure;cmd.Parameters.Add("@AutoID",SqlDbType.Int,4).Value = par_id.Text;//***********************************************if(this.par_lhb.SelectedItem.Text=="—请选推出年份—")
{
cmd.Parameters.Add("@AutoYear",SqlDbType.Int,4).Value = System.DBNull.Value;
}
else
{
cmd.Parameters.Add("@AutoYear",SqlDbType.Int,4).Value = par_lhb.SelectedItem.Text;
}
lhb = cmd.ExecuteNonQuery();
con.Close();

解决方案 »

  1.   

    SqlCommand cmd = new SqlCommand("select  AutoID from tab where AutoID="+par_id.Text ,con);
    if ( cmd.ExecuteNonQuery()>0)
    {
    Response.Redirect(" aaa.aspx");}  
    *****************************************************************************
    欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) 最新版本:20070212http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
      

  2.   

    SqlCommand cmc = new SqlCommand("select AutoID from cheParameter where AutoID="+par_id.Text,con);
    if (cmc.ExecuteNonQuery()>0)
    {
    Response.Redirect("http://www.163.cn");
    }
      

  3.   


    private void Page_Load(object sender, System.EventArgs e)
    {
    par_id.Text = Request.QueryString["cheID"].ToString();if(!IsPostBack)
    {
    SqlConnection con = DataCon.AutoCon();
    con.Open();SqlCommand cma = new SqlCommand("select * from cnat_nf",con);
    SqlDataReader sda = cma.ExecuteReader();
    this.par_lhb.DataSource = sda;
    this.par_lhb.DataTextField = "cnat_nf";
    this.par_lhb.DataValueField = "cnat_id";
    this.par_lhb.DataBind();
    this.par_lhb.Items.Insert(0,new ListItem("—请选推出年份—","-1"));
    sda.Close();SqlCommand cmd = new SqlCommand("select * from cnat_name",con);
    SqlDataReader sdr = cmd.ExecuteReader();
    this.par_jay.DataSource = sdr;
    this.par_jay.DataTextField = "par_lhb";
    this.par_jay.DataValueField = "par_id";
    this.par_jay.DataBind();
    this.par_jay.Items.Insert(0,new ListItem("—请选录入人—","-1"));
    sdr.Close();SqlCommand cmc = new SqlCommand("select AutoID from cheParameter where AutoID="+par_id.Text,con);
    if (cmc.ExecuteNonQuery() > 0)
    {
    Response.Redirect("http://www.163.cn");
    }con.Close();
    }
    不管用呀!!!
    cheParameter它是数据库的表名字!