Tuesday, February 14, 2012

Insert data in Sql Server 2005 using ASP.Net

Insert data in Sql server 2005

After insert:-

Step 1) Install and configure Sqlserver 2005
Step 2)Write following code to fetch data from database
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class sqlserver : System.Web.UI.Page

    SqlConnection con = new SqlConnection();
    SqlCommand cmd = new SqlCommand();
    public string query;

    protected void connection()
        con.ConnectionString = "server=.\\SQLEXPRESS; integrated security=SSPI; initial catalog=sourav;";
        cmd.Connection = con;

    protected void Page_Load(object sender, EventArgs e)
        //Calling connection function

        //Change below line according to your table  and data
        cmd.CommandText = "insert into loginfo values('abc','xyz')";

No comments:

Post a Comment