<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Save"
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("Data Source=NITIN;Initial Catalog=test;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.FileName == "")
{
Label1.Visible = true;
}
else
{
string fpath = "~\\Upload\\" + FileUpload1.FileName;
FileUpload1.PostedFile.SaveAs(Server.MapPath(fpath));
string query = "insert into fst values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + fpath + "')";
SqlDataAdapter da = new SqlDataAdapter(query, con);
DataSet ds = new DataSet();
da.Fill(ds);
Response.Write("Values Inserted");
DisplayNextPage();
}
}
public void DisplayNextPage()
{
con.Open();
SqlCommand cmd = new SqlCommand("select*from fst", con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
if (TextBox1.Text == dr[0].ToString())
{
Session["name"] = dr[0].ToString();
Session["city"] = dr[1].ToString();
Session["img"] = dr[2].ToString();
Response.Redirect("Default2.aspx");
}
}
con.Close();
}
}
default2.aspx page
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Welcome
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
Your City is
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<br />
<br />
<asp:Image ID="Image1" runat="server" Height="121px" Width="108px" />
<br />
<br />
Data Bound Control<br />
<asp:DataList ID="DataList1" runat="server" Width="280px">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
<asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
<asp:Image ID="Image2" runat="server" Height="70px" Width="54px" />
<br />
<br />
</ItemTemplate>
</asp:DataList>
<br />
</div>
</form>
</body>
</html>
default2.aspx.cs
public partial class Default2 : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("Data Source=NITIN;Initial Catalog=test;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = Session["name"].ToString();
Label2.Text = Session["city"].ToString();
Image1.ImageUrl = Session["img"].ToString();
display();
}
public void display()
{
SqlDataAdapter da = new SqlDataAdapter("Select * from fst", con);
DataSet ds = new DataSet();
da.Fill(ds);
DataList1.DataSource = ds;
DataList1.DataBind();
}
}
My Sql data query
create database test
use test
create table fst (sname varchar(50),city varchar(50),snap varchar(100))
select*from fst