Total Pageviews

28 February 2013

How to use store procedure in asp.net with example


Default2.aspx=>

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:Label ID="Label1" runat="server" Text="ID"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /><br />
<asp:Label ID="Label2" runat="server" Text="Password"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br /><br />
<asp:Label ID="Label3" runat="server" Text="Confirm Password"></asp:Label>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br /><br />
<asp:Label ID="Label4" runat="server" Text="Email ID"></asp:Label>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox><br /><br /><br />
<asp:Label ID="l1" runat="server"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Submit Record" OnClick="Button1_Click" />
<asp:Button ID="show" runat="server" Text="Show" onclick="show_Click" /><br />
<div id="d1" runat="server">
<asp:GridView ID="DetailsView1" runat="server" Height="16px">
</asp:GridView></div>
</asp:Content>
 Default2.aspx.cs=>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
public partial class Default2 : System.Web.UI.Page
{
string s = ConfigurationManager.ConnectionStrings["conn"].ToString();
SqlConnection con;
//DataSet ds = new DataSet();
////Here we declare the parameter which we have to use in our application
SqlCommand cmd = new SqlCommand();
//SqlParameter sp1 = new SqlParameter();
//SqlParameter sp2 = new SqlParameter();
//SqlParameter sp3 = new SqlParameter();
//SqlParameter sp4 = new SqlParameter();
protected void Page_Load(object sender, EventArgs e)
{
d1.Visible = false;
if (!IsPostBack)
{
Bindlogin();
}
 }
private void Bindlogin()
{
con =new SqlConnection(s);
con.Open();
SqlCommand cmd = new SqlCommand("select * from login", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
if (ds.Tables[0].Rows.Count > 0)
{
DetailsView1.DataSource = ds;
DetailsView1.DataBind();
}
else
{
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
DetailsView1.DataSource = ds;
DetailsView1.DataBind();
int columncount = DetailsView1.Rows[0].Cells.Count;
DetailsView1.Rows[0].Cells.Clear();
DetailsView1.Rows[0].Cells.Add(
new TableCell());
DetailsView1.Rows[0].Cells[0].ColumnSpan = columncount;
DetailsView1.Rows[0].Cells[0].Text = 
"No Records Found";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
con =new SqlConnection(s);
cmd =new SqlCommand("submitrecord", con);
cmd.CommandType =CommandType.StoredProcedure;
cmd.Parameters.Add("@ID", SqlDbType.VarChar).Value = TextBox1.Text;
cmd.Parameters.Add("@Password", SqlDbType.VarChar).Value = TextBox2.Text;
cmd.Parameters.Add("@ConfirmPassword", SqlDbType.VarChar).Value = TextBox3.Text;
cmd.Parameters.Add("@email", SqlDbType.VarChar).Value = TextBox4.Text;
con.Open();
 cmd.ExecuteNonQuery();
l1.Text = 
"Insert Successfully";
con.Close();
 }
protected void show_Click(object sender, EventArgs e)
{
d1.Visible = true;
}
}


 

How Create Crystal Report in Vissual Studio 2010 with example

Home page
Add caption



























How to Send smtp Mail with the help of asp.net with example



Web configuration=>Here we are setting the smtp port for sending mail in with spacific domain there are several steps are given as blow-
Step First-
<system.net>
    <mailSettings>
      <smtp>
        <network host="smtp.domain.com" port="25" userName="domain id" password="domain password" />
      </smtp>
    </mailSettings>
  </system.net>
  <appSettings>
    <add key="amrit" value="ID@domain.com"/>
  </appSettings>

  <system.webServer>
     <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
Step Second-Here we sre designing in Asp.net page.
<div>
To<asp:Textbox id="TextBox3.Text" runat="server" />
Subject<asp:Textbox id="TextBox1.Text" runat="server" />
Body<asp:Textbox id="TextBox2.Text" runat="server" />
<asp:Button ID="Button2" runat="server" onclick="Button2_Click"
            Text="Send Mail" />
</div>
Step Third-
using System.Net.Mail;
 protected void Button2_Click(object sender, EventArgs e)
    {
string fromEmail = ConfigurationManager.AppSettings["amrit"].ToString();
        string toEmail = TextBox3.Text;

        MailMessage message = new MailMessage(fromEmail, toEmail);
        message.Subject = TextBox1.Text;
        message.Body = TextBox2.Text;
       
        SmtpClient smtp = new SmtpClient();
        smtp.Send(message);
}

Contact Form

Name

Email *

Message *