ASP.NET Code Only
With Out Argument
Class Lavel Declare
{
SqlConnection con;
SqlCommand cmd;
}
Constractor Part()
{
con=new SqlConnection("datasource=.\\sqlexpress;initial catalog=database_name; integrated security=sspi");
}
Function Part()
{
cmd=new SqlCommand();
Function Part()
{
cmd=new SqlCommand();
cmd.Connection=con;
cmd.CommandText="Pass The Query "
}
Single Argument Pass
Class Lavel Declare
{
SqlConnection con;
SqlCommand cmd;
}
Constractor Part()
{
con=new SqlConnection("datasource=.\\sqlexpress;initial catalog=database_name; integrated security=sspi");
}
Function Part()
{
Function Part()
{
cmd.Connection=con;
cmd=new SqlCommand("Pass The Query");
}
Double Argument
Class Lavel Declare
{
SqlConnection con;
SqlCommand cmd;
}
Constractor Part()
{
con=new SqlConnection("datasource=.\\sqlexpress;initial catalog=database_name; integrated security=sspi");
}
Function Part()
{
Function Part()
{
cmd=new SqlCommand("Pass The Query", con);
}
GRIED VIEW
IMAGE LOAD IN DATA BASE AND SHOW IN GRIDVIEW
ASPX PAGE CODE :::::::<asp:GridView ID="g1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<HeaderTemplate>IMAGE
</HeaderTemplate>
<ItemTemplate>
<asp:Image ID="imd" runat="server" ImageUrl='<%# bind("image") %>' Height="20%" Width="30%" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
.CS Page Code :::
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
SqlConnection con;
SqlCommand cmd;
SqlDataReader rd;
DataTable dt;
SqlDataAdapter da;
public _Default()
{
con = new SqlConnection("data source=.\\sqlexpress; initial catalog=demo1; integrated security=SSPI; ");
dt = new DataTable();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
fill();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
con.Open();
FileUpload1.SaveAs(Server.MapPath("a/")+FileUpload1.FileName);
cmd = new SqlCommand("insert into img values('" + "a/" + FileUpload1.FileName + "')", con);
int i =cmd.ExecuteNonQuery();
if (i != 0)
{
fill();
}
}
public void fill()
{
da = new SqlDataAdapter("select * from img", con);
da.Fill(dt);
g1.DataSource = dt;
g1.DataBind();
}
}
Useing CheckBox Delete The Data Form GriedView
ASPX PAGE CODE :::::::
<asp:GridView ID="g1" runat="server" AutoGenerateColumns="false"
OnRowDeleting="delete">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:Button ID="b1" runat="server" Text="DELETE" CommandName="delete" /><br />
<asp:CheckBox ID="all" runat="server" AutoPostBack="true" OnCheckedChanged="All_Check" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="one" runat="server" AutoPostBack="true" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate> IMAGE</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="l1" runat="server" Text='<%#bind("image") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
.CS Page Code :::
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("data source=.\\sqlexpress; initial catalog=demo1; integrated security=SSPI");
SqlCommand cmd;
SqlDataReader rd;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
fill();
}
}
public void All_Check(object sender, EventArgs e)
{
CheckBox All = g1.HeaderRow.FindControl("all") as CheckBox;
for (int i = 0; i < g1.Rows.Count; i++)
{
CheckBox One = g1.Rows[i].FindControl("one") as CheckBox;
if (All.Checked == true)
{
One.Checked = true;
}
else
{
One.Checked = false;
}
}
}
public void fill()
{
con.Open();
cmd = new SqlCommand("select * from img", con);
rd=cmd.ExecuteReader();
rd.Read();
g1.DataSource = rd;
g1.DataBind();
con.Close();
}
protected void delete(object sender, GridViewDeleteEventArgs e)
{
for (int k = 1; k < g1.Rows.Count; k++)
{
CheckBox One = g1.Rows[k].FindControl("one") as CheckBox;
if (One.Checked == true)
{
Label l=g1.Rows[k].FindControl("l1") as Label;
con.Open();
cmd = new SqlCommand("delete from img where image='" + l.Text + "'", con);
cmd.ExecuteNonQuery();
con.Close();
}
}
fill();
}
STATEMANEGMENT
Create Single Value In Cookies :::::
Buttom code ::: Cookies Has Single Value
HttpCookie c = new HttpCookie("c1");
c.Value = TextBox1.Text;
c.Expires = System.DateTime.Now.AddHours(3);
Request.Cookies.Add(c);
Response.Redirect("Default2.aspx");
Next Page Load event Code::
if (!IsPostBack)
{
Response.Write(Request.Cookies["c1"].Value.ToString());
}
End Cookies Code :::::
Create Multi Value In Cookies :::::::
HttpCookie aCookie = new HttpCookie("userInfo");
aCookie.Values["userName"] = "patrick";
aCookie.Values["lastVisit"] = DateTime.Now.ToString();
aCookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(aCookie);
aCookie.Values["userName"] = "patrick";
aCookie.Values["lastVisit"] = DateTime.Now.ToString();
aCookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(aCookie);
Response.Redirect("Default2.aspx");
Next Page Load event Code::
if (!IsPostBack)
{
Response.Write(Request.Cookies["userInfo"]["userName"]); Response.Write(Request.Cookies["userInfo"]["lastVisit"]);
}
End Cookies Code
MAILING CODE
Code Past ON Button :::::MailMessage m = new MailMessage(From, To, Subject Text, Body Text);
try
{
NetworkCredential n = new NetworkCredential("Your ID", "PassWord");
SmtpClient s = new SmtpClient("smtp.gmail.com", 587);
s.EnableSsl = true;
s.UseDefaultCredentials = false;
s.Credentials = n;
s.Send(m);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
Labels: Asp.net
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home