asp.net How to use check availlable controle use?
i'm create one web site in library management system at the one page Issue of book ok the book is available or not available .how to check and then how to set validate controle My coding is
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 = "";
}
}
In your code there are a few things which look eerm strange. For instance (!(IsPostBack == true))
should probably be if (!IsPostBack)
. Also, you should probably check for the existence of the query string parameter and get it by name Request.QueryString["name"]
do this instead
string id = Request.QueryString["id"];
if (id == null)
{
// do error handling here, no id specified;
}
else
{
// use id;
}
... and more
Could you be more specific as to what the actual problem is, other than that it does not run?
精彩评论