In This Article i am going to tell you how you can search data from your database and show on second page by using ASP.Net and C#.Net Code.
Follow the instruction step by step to get it done.
Code
on search page click on search Button:
Session["id"] = TextBox1.Text.ToString();
Session["name"] = TextBox2.Text.ToString();
Session["course"] = TextBox3.Text.ToString();
|
Response.Redirect("Second.aspx");
Code
on second page on Page load event:
string val1,
val2, val3;
val1 = Session["id"].ToString();
val2 = Session["name"].ToString();
val3 = Session["course"].ToString();
SqlConnection
cnn = new SqlConnection();
cnn.ConnectionString = "Server=sandeep-pc; Database=Information; User
Id=sa; password= sa"; ;
cnn.Open();
SqlCommand
cmd = new SqlCommand();
cmd.CommandText = "select * from Std_Fee_Details where DTstdid='"
+ val1 + "' or DTstdname='" + val2
+ "'or DTcourse='" + val3 + "'";
cmd.Connection = cnn;
SqlDataReader
myReader = cmd.ExecuteReader();
if
(myReader.HasRows == false)
{
Response.Write("<script>alert(‘Data is NOT
Found’)</script>");
// Response.Write(@"<script language='javascript'>alert('Sorry
Records NOT Found !!!!!!!')</script>");
}
else
{
while
(myReader.Read())
{
Label6.Text = myReader["DTstdid"].ToString();
Label7.Text = myReader["DTstdname"].ToString();
Label8.Text = myReader["DTcourse"].ToString();
Label9.Text = myReader["DTsem"].ToString();
Label10.Text = myReader["DTtotalfee"].ToString();
}
}
myReader.Close();
cnn.Close();
}
No comments:
Post a Comment