OleDbCommand mycommand=new OleDbCommand("update [card] set jf=jf+" + jf.Text + " where cardid='"+cardid.Text+"'",obj.myconn); 
try
{
mycommand.ExecuteNonQuery();
mycommand.Dispose();
obj.myconn.Close();
obj.myconn.Dispose();
Response.Write("<script>alert('添加成功!');location='admin_user.aspx'</script>");
}
catch(System.Data.SqlClient.SqlException)
{
mycommand.Dispose();
obj.myconn.Close();
obj.myconn.Dispose();
Response.Write("<script>alert('对不起,操作出现错误,请返回!!');location='admin_user.aspx'</script>");
}这样在cardid不等于cardid.Text的情况下,也会提示添加成功,怎么实现如果没有这个号码提示无此号的提示呢?

解决方案 »

  1.   

    mycommand.ExecuteNonQuery();
    先将它的执行结果赋于一个整形变量,只要这个整形变量的值不等于-1,就表示执行成功.反之.
      

  2.   

    string sql="select * from [card] where cardid='"+cardid.Text+"'";string constring=System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
    OleDbDataAdapter    sda =new OleDbDataAdapter(sql,constring);
    DataSet ds=new DataSet();
    sda.Fill(ds);
    if(ds.Tables.Count>0 && ds.Tables[0].Rows.Count>0)
    {
         //调用更新语句
    }
    else
    {
              //显示没有该记录信息
    }
      

  3.   

    OK谢谢了,
    还有一个问题。
    <asp:ListBox id="fl" runat="server" Width="104px" Height="40px" Rows="1">
    <asp:ListItem Value="普通卡" Selected="True">普通卡</asp:ListItem>
    <asp:ListItem Value="贵宾卡">贵宾卡</asp:ListItem>
    <asp:ListItem Value="失效卡">失效卡</asp:ListItem>
    </asp:ListBox>
    fl.SelectedItem.Text = rs["types"].ToString();
    读取数据的时候,如果用这个,rs["types"]字段值等于贵宾卡的时候,那在选择框里就变成
    <asp:ListItem Value="贵宾卡" Selected="True">贵宾卡</asp:ListItem>
    <asp:ListItem Value="贵宾卡">贵宾卡</asp:ListItem>
    <asp:ListItem Value="失效卡">失效卡</asp:ListItem>
    了,有什么办法让选择框还是原来三个选项,保是让跟数据库字段里同样的选择被选中?
      

  4.   

    OK谢谢了,
    还有一个问题。
    <asp:ListBox id="fl" runat="server" Width="104px" Height="40px" Rows="1">
    <asp:ListItem Value="普通卡" Selected="True">普通卡</asp:ListItem>
    <asp:ListItem Value="贵宾卡">贵宾卡</asp:ListItem>
    <asp:ListItem Value="失效卡">失效卡</asp:ListItem>
    </asp:ListBox>
    fl.SelectedItem.Text = rs["types"].ToString();
    读取数据的时候,如果用这个,rs["types"]字段值等于贵宾卡的时候,那在选择框里就变成
    <asp:ListItem Value="贵宾卡" Selected="True">贵宾卡</asp:ListItem>
    <asp:ListItem Value="贵宾卡">贵宾卡</asp:ListItem>
    <asp:ListItem Value="失效卡">失效卡</asp:ListItem>
    了,有什么办法让选择框还是原来三个选项,保是让跟数据库字段里同样的选择被选中?
      

  5.   

    <asp:ListBox id="fl" runat="server" Width="104px" Height="40px" Rows="1">
    <asp:ListItem Value="普通卡" Selected="True">普通卡</asp:ListItem>
    <asp:ListItem Value="贵宾卡">贵宾卡</asp:ListItem>
    <asp:ListItem Value="失效卡">失效卡</asp:ListItem>
    </asp:ListBox>
    fl.SelectedItem.Text = rs["types"].ToString();读取数据的时候,如果用这个,rs["types"]字段值等于贵宾卡的时候,那在选择框里就变成<asp:ListItem Value="贵宾卡" Selected="True">贵宾卡</asp:ListItem>
    <asp:ListItem Value="贵宾卡">贵宾卡</asp:ListItem>
    <asp:ListItem Value="失效卡">失效卡</asp:ListItem>了,有什么办法让选择框还是原来三个选项,保是让跟数据库字段里同样的选择被选中?