asp.net如何使用check availlable controle使用?

时间:2011-03-10 10:37:38

标签: asp.net

我在一个页面的图书馆管理系统中创建了一个网站 这本书可用或不可用。如何检查,然后如何设置验证控制 我的编码是

public partial class Issueofbook : System.Web.UI.Page
{
    public Int64 Sid;

    protected void Page_Load(object sender, EventArgs e)
    {
        string Id;
        Id = Request.QueryString.Get(0);

        if (!(IsPostBack == true))
        {
            if (Request.QueryString.Get(1) == "G")
            {
                Sid = Convert.ToInt64(Id);
                if (PopulatedRecord(Sid) == false)
                {

                }
            }
        }
    }
    private Boolean PopulatedRecord(Int64 Id)
    {
        DataSet DS;
        DS = new DataSet();
        SqlCommand cmd = new SqlCommand();
        SqlDataAdapter da = new SqlDataAdapter();
        SqlConnection Cnn = new SqlConnection();
        string connectionstring;
        connectionstring = @"Datasource=DEVI\SQLEXPRESS;Intial                                                
                    catalog=librarymanagement;Integrated Security=SSPI";
        Cnn.ConnectionString = connectionstring;
        if (Cnn.State != ConnectionState.Open)
            Cnn.Open();
        cmd.Connection = Cnn;
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "usbinsertdatainto";
        cmd.Parameters.Clear();
        cmd.Parameters.AddWithValue("@bookno", txtno);
        da.SelectCommand = cmd;
        try
        {
            da.Fill(DS);
        }
        catch (Exception ex)
        {
            throw new ApplicationException(
               "!!! An Error Occured While Update Record In Dtl_SecurityCapital_Upload." +
           ex.Message);
            lblerror.Visible = true;
            lblerror.Text = "!!! An Error Occured While " + ex.Message.ToString();
            return false;
        }
        if (DS.Tables[0].Rows.Count > 0)
        {
            txtno.Text = DS.Tables[0].Rows[0]["bookno"].ToString();
            txtstuno.Text = DS.Tables[0].Rows[0]["studentno"].ToString();
            RadioButton1.Text = DS.Tables[0].Rows[0]["copiesavaillable"].ToString();
            RadioButton2.Text = DS.Tables[0].Rows[0]["copiesavaillable"].ToString();
            txtdate.Text = DS.Tables[0].Rows[0]["IssueDate"].ToString();
            txtddate.Text = DS.Tables[0].Rows[0]["Duedate"].ToString();
        }
        cmd.Dispose();
        Cnn.Close();
        Cnn.Dispose();
        return true;
    }

    protected void Btn_click(object sender, EventArgs e)
{
    SqlCommand cmd = new SqlCommand();
    SqlConnection cnn = new SqlConnection();
    string connectionstring;
    connectionstring =  ConfigurationManager.ConnectionStrings["librarymanagementconnectionstring"].ConnectionStri  
       ng;
    cnn.ConnectionString = connectionstring;
    if (cnn.State != ConnectionState.Open)
        cnn.Open();
    cmd.Connection = cnn;
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.CommandText = "spupdatebookdetail";
    cmd.Parameters.Clear();
    cmd.Parameters.AddWithValue("@bookno", txtno.Text);
    cmd.Parameters.AddWithValue("@studentno", txtstuno.Text);
    cmd.Parameters.AddWithValue("@Issuedate", txtdate.Text);
    cmd.Parameters.AddWithValue("@Duedate", txtddate.Text);
    if(RadioButton1.Checked ==true)
    {
        cmd.Parameters.AddWithValue("@copiesavaillable", RadioButton1.Text);
    }
    if (RadioButton2.Checked==true)
    {
        cmd.Parameters.AddWithValue("@copiesavillable", RadioButton2.Text);
    }
    try
    {
        cmd.ExecuteNonQuery();
    }
    catch (Exception ex)
    {
        throw new ApplicationException("!!! An error an occured while update the record In Dtl _captial upload." + ex.Message);
        lblerror.Visible = true;
        lblerror.Text  = "!!! An error an occured while." + ex.Message.ToString();
    }
    lblerror.Visible  = true;
    lblerror.Text  = "Record update sucessfully";
    PopulatedRecord(Sid);
}

    protected void Button_click(object sender, EventArgs e)
    {
        Server.Transfer("useraccount.aspx");
    }

    protected void Button2_Click(object sender, EventArgs e)
    {

        SqlConnection cnn = new SqlConnection();
        string constr = null;
        SqlCommand cmd = new SqlCommand();
        constr = @"Data Source=DEVI\SQLEXPRESS; Initial Catalog =librarymanagement; Integrated Security=SSPI";
        cnn.ConnectionString = constr;
        try
        {
            if (cnn.State != ConnectionState.Open)
                cnn.Open();
        }
        catch (Exception ex)
        {
            string str1 = null;
            str1 = ex.ToString();
        }
        cmd.Connection = cnn;
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "uspInsertbookDatainto";
        cmd.Parameters.Clear();
        cmd.Parameters.AddWithValue("@bookno", txtno.Text);
        cmd.Parameters.AddWithValue("@studentno", txtstuno.Text);
        cmd.Parameters.AddWithValue("@Issuedate", txtdate.Text);
        cmd.Parameters.AddWithValue("@Duedate", txtddate.Text);
        if (RadioButton1.Checked == true)
        {
            cmd.Parameters.AddWithValue("@copiesavaillable", RadioButton1.Text);
        }
        if (RadioButton2.Checked == true)
        {
            cmd.Parameters.AddWithValue("@copiesavaillable", RadioButton2.Text);
        }
        try
        {
            cmd.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            throw new ApplicationException("!!! An error an occured while Insert Record Dtl_SecurityCapital_Upload." + ex.Message);
            lblerror.Visible = true;
            lblerror.Text = "!!! An Error occured while ." + ex.Message.ToString();
        }

        finally
        {
            cmd.Dispose();
        }
        cnn.Close();
        lblerror.Text = "New Issue of record suceessfully!!";
        txtno.Text = "";
        txtstuno.Text = "";
        txtdate.Text = "";
        txtddate.Text = "";
    }

}

1 个答案:

答案 0 :(得分:0)

在你的代码中有一些看起来很奇怪的东西。例如,(!(IsPostBack == true))应该是(!IsPostBack)。此外,您应该检查是否存在查询字符串参数,并按名称Request.QueryString["name"]获取它 这样做

string id = Request.QueryString["id"];
if (id == null) 
{
    // do error handling here, no id specified;
}
else
{
    // use id;
}

......还有更多

你能否更具体地说明实际问题是什么,除了它没有运行?