How to create DataBase in Sql Server


 How to Create DataBase in Sql Server



You may be required to create a new Microsoft SQL database. This article explains how to create a new database on the following versions of Microsoft SQL Server:
  • Microsoft SQL Server 2000
  • Microsoft SQL Server 2005
  • Microsoft SQL Server 2008
Microsoft SQL Server 2000
  1. Open Microsoft SQL Management Studio
  2. Expand the Microsoft SQL Server node where you want to create the database
  3. Right click the Databases node and then click New Database  


 4.  Type the database name in the dialog box, for example,  Visualstudioexpert_demo , and then click OK

Microsoft SQL Server 2005
  1. Open Microsoft SQL Management Studio
  2. Connect to the database engine using database administrator credentials
  3. Expand the server node
  4. Right click Databases and select New Database



  5. Enter a database name and click on OK to create the database

Microsoft SQL Server 2008
  1. Open Microsoft SQL Management Studio
  2. Connect to the database engine using database administrator credentials
  3. Expand the server node
  4. Right click Databases and select New Database
  5. Enter a database name and click OK to create the database

How Send Mail in ASP .Net


Sending an E-Mail Using ASP.Net

This tutorial will show you how to send a simple email message using ASP.NET 2.0 and C#

Introduction

Sending email is a very common task in any web application for many purposes.
Sending e-mails with ASP.NET is pretty straight forward. The .NET framework comes with an entire namespace for handling e-mails, the System.Net.Mail namespace. In the following examples, we will use two classes from this namespace: The MailMessage class, for the actual e-mail, and the SmtpClient class, for sending the e-mail. As you may be aware, mails are sent through an SMTP server, and to send mails with the .NET framework, you will need access to an SMTP server. If you're testing things locally, the company that supplies your with Internet access, will usually have an SMTP server that you can use, and if you wish to use one of these examples on your actual website, the company that hosts your website will usually have an SMTP server that you can use. Go through the support pages to find the actual address - it's usually something along the lines of smtp.your-isp.com or mail.your-isp.com.
First, you will need to import the System.Net.Mail namespace.

 protected void MailSendBtn_Click(object sender, EventArgs e)
    {
     
try
    {
        MailMessage mailMessage = new MailMessage();
        mailMessage.To.Add("your.own@mail-address.com");
        mailMessage.From = new MailAddress("another@mail-address.com");
        mailMessage.Subject = "ASP.NET e-mail test";
        mailMessage.Body = "Hello world,\n\nThis is an ASP.NET test e-mail!";
        SmtpClient smtpClient = new SmtpClient("smtp.your-isp.com");
        smtpClient.Send(mailMessage);
        Response.Write("E-mail sent!");
    }
    catch(Exception ex)
    {
        Response.Write("Could not send the e-mail - error: " + ex.Message);
    }
}

Update Multiple Rows in ASP.Net GridView using CheckBoxes


Bulk Edit Update Multiple Rows in ASP.Net GridView using CheckBoxes


How to Bulk Edit Update Multiple Rows or records in ASP.Net GridView at once using CheckBoxes on single click. In this example he has explained how we can use TextBox and DropDownList in Edit mode.
In this article I will explain how to edit and update multiple rows in ASP.Net GridView using CheckBoxes i.e. the Rows which are checked will become editable and user can update multiple rows on one single Update button click.


HTML PAGE  CODE:


<asp:GridView ID="grvEmploye" runat="server" AutoGenerateColumns="false" 
OnRowDataBound = "OnRowDataBound" DataKeyNames ="empId">
    <Columns>
        <asp:TemplateField>
            <HeaderTemplate>
                <asp:CheckBox ID = "chkAll" runat="server" AutoPostBack=
"true" OnCheckedChanged="OnCheckedChanged" />
            </HeaderTemplate>
            <ItemTemplate>
                <asp:CheckBox runat="server" AutoPostBack="true" OnCheckedChanged="OnCheckedChanged" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Name" ItemStyle-Width = "150">
            <ItemTemplate>
                <asp:Label runat="server" Text='<%# Eval("Name")%>'></asp:Label>
 <asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("Name")%>'
 Visible="false"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Country" ItemStyle-Width = "150">
            <ItemTemplate>
                <asp:Label ID = "lblCountry" runat="server" Text='<%# Eval("CountryName") %>'></asp:Label>
                <asp:DropDownList ID="ddlCountry" runat="server" Visible = "false">
                </asp:DropDownList>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
<br />
<asp:Button ID="btnUpdt" runat="server" Text="Update" OnClick = "Update"
 Visible = "false"/>



Binding the ASP.Net GridView
Below is the code to bind the ASP.Net GridView control with records from the Employe table of the My_Demo database.

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        this.BindGrid();
    }
}
private void BindGrid()
string sql="SELECT empId, Name, Country FROM Employe"
    SqlCommand cmd = new SqlCommand(sql);


 DataTable dt = new DataTable();
        SqlDataAdapter ada = new SqlDataAdapter(cmd);
        ada.Fill(dt);
        grvEmploye.DataSource = dt;
        grvEmploye.DataBind();

}


Fill the Country DropDownList in the ASP.Net GridView Row
In the OnRowDataBound event of the ASP.Net GridView I am populating the Country DropDownList which will be displayed when a row is edited.



protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        SqlCommand cmd = new SqlCommand("SELECT DISTINCT(Country) FROM Employe");
        DropDownList ddlCountry= (e.Row.FindControl("ddlCountry"as DropDownList);
        ddlCountry.DataSource = this.ExecuteQuery(cmd, "SELECT");
        ddlCountry.DataTextField = "Country";
        ddlCountry.DataValueField = "Country";
        ddlCountry.DataBind();
        string country = (e.Row.FindControl("lblCountry"as Label).Text;
        ddlCountry.Items.FindByValue(country).Selected = true;
    }
}



Change the ASP.Net GridView Row to Edit mode on CheckBox checked
The below event handler is executed when the CheckBox is the ASP.Net GridView Row is checked or unchecked all.
 looping through the GridView Rows and checking whether the CheckBox is checked for that Row. If the CheckBox is checked then the Label control in the GridView Cell is hidden and the corresponding TextBox or DropDownList is made visible.
the Update button btnUpdate is only visible when at least 1 checkbox is checked true.

protected void OnCheckedChanged(object sender, EventArgs e)
{
    bool isUpdateVisible = false;
    CheckBox chk = (sender as CheckBox);
    if (chk.ID == "chkAll")
    {
        foreach (GridViewRow row in grvEmploye.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                row.Cells[0].Controls.OfType<CheckBox>().FirstOrDefault().Checked = chk.Checked;
            }
        }
    }
    CheckBox chkAll = (gvCustomers.HeaderRow.FindControl("chkAll"as CheckBox);
    chkAll.Checked = true;
    foreach (GridViewRow row in grvEmploye.Rows)
    {
        if (row.RowType == DataControlRowType.DataRow)
        {
            bool isChecked = row.Cells[0].Controls.OfType<CheckBox>().FirstOrDefault().Checked;
            for (int i = 1; i < row.Cells.Count; i++)
            {
                row.Cells[i].Controls.OfType<Label>().FirstOrDefault().Visible = !isChecked;
                if (row.Cells[i].Controls.OfType<TextBox>().ToList().Count > 0)
                {
                    row.Cells[i].Controls.OfType<TextBox>().FirstOrDefault().Visible = isChecked;
                }
                if (row.Cells[i].Controls.OfType<DropDownList>().ToList().Count > 0)
                {
                    row.Cells[i].Controls.OfType<DropDownList>().FirstOrDefault().Visible = isChecked;
                }
                if (isChecked && !isUpdateVisible)
                {
                    isUpdateVisible = true;
                }
                if (!isChecked )
                {
                    chkAll.Checked = false;
                }
            }
        }
    }
    btnUpdate.Visible = isUpdateVisible;
}



Updating the edited records in ASP.Net GridView Row
The below event handler is executed when the Update button btnUpdate is clicked.

protected void Update(object sender, EventArgs e)
{
    foreach (GridViewRow row in grvEmploye.Rows)
    {
        if (row.RowType == DataControlRowType.DataRow)
        {
            bool isChecked = row.Cells[0].Controls.OfType<CheckBox>().FirstOrDefault().Checked;
            if (isChecked)
            {
                SqlCommand cmd = new SqlCommand("UPDATE Employe SET Name = '"+ (row.Cells[1].Controls.OfType<TextBox>().FirstOrDefault().Text) +"', Country = '"+ (row.Cells[1].Controls.OfType<DropDownList>().FirstOrDefault().SelectedItem.Value) +"' WHERE empId = '"+grvEmploye.DataKeys[row.RowIndex].Value+"'");
cmd.ExecuteNonQuery();

               
            }
        }
    }
    btnUpdate.Visible = false;
    BindGrid();
}