Welcome to Discuss Everything Forums...

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.


 

Tags for this Thread

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    raghu p
    raghu p's Avatar
    Guest

    How can i connect database from Sql server to asp.net pages?

    I have created the web page using asp.net and also database using Sql server want to input through text box from asp.net and insert the same to database i am new to this please guide (created data base using windows authentication in sql server)

  2. #2
    Smutty
    Smutty's Avatar
    Guest
    1) Create an SqlConnection object. Supply a connection string to the object

    SqlConnection cn = new SqlConnection("server=YourServer; Database=YourDB; Integrated Security = True" );

    2) Create a command object to hold and execute your query
    SqlCommand cmd = cn.CreateCommand();
    cmd.CommandText = "Your Query Here";


    3)Open the connection:
    cn.Open();

    4)Execute your query
    cmd.ExecuteReader(); //if the query retrieves a record set
    cmd.ExecuteNonQuery(); //if the query is a Data modification SQL

    5) Close the connection
    cn.Close();

    Hope this helps.

 

 

Quick Reply Quick Reply

Click here to log in


In what corner do we have Search box?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. how to connect Sql database in ASP.NET?
    By Saed G in forum Discuss ASP
    Replies: 1
    Last Post: 06-26-2011, 08:19 AM
  2. Replies: 0
    Last Post: 11-25-2010, 05:17 AM
  3. Replies: 0
    Last Post: 05-27-2010, 10:24 AM
  4. Replies: 1
    Last Post: 03-07-2009, 01:30 PM
  5. Replies: 0
    Last Post: 12-18-2008, 03:15 PM

Bookmarks

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •