Database Connection in Asp.Net C#

 Open  Visual Studio 

Go to - File - New - Website - Select  Asp.Net Website – Name change – DbConnection - OK.

Next - Add To New Form - Go to Solution Explorer  - Select Project Name - Right Click - Add - Add New Item - Click - Select -Web Form - Rename - Register.aspx   -  Click - ADD - Display The Form in Solution Explorer-Register.aspx

Below Screen Is Design Coding Page

       Next - Click Design  Show like that Below

Next - Click Tool Box and then Select Label,TextBox,Button Double Click  Show like that Below

Next - Select Label or Textbox or Button  Press F4 Button - Property Window Open

Property Window Change the Name  Text = Name, 

Like that Same For all Label  and Button Press F4 

 Change Name for Text

Next  - Add to the Database  Go To-Solution Explorer -Project Name-Right Click-Add-Add New Item-Select Sql Server Database .mdf  -Add-To Display Solution Explorer -First Load 1 Minutes After Display Database.mdf

                   Yes Button Click

Next - Select Table - Right Click - Add New Table -Click - Open Like that

Next - Fill Column Name to  Required Column Name Like That Below

Id name want to Use or Delete right click  Like that Below

Next - Visual Studio 2005,2008,2010  press save Button After Filling the Column Name Like that Below

Click  Show Table1 delete after fill register    -Next -Again Click Save Button

Visual Studio 2012  fill table name like that  below

Next - Change Name from Table to register

Next - Click Update Button and Update  DataBase Button Click

Next - Refresh Button Press

Next - Click Database -Table - register  

Next - want to any update in Column name - Select - table - table name(register) - Right Click -Open Table Defination - Click-Show - Visual Studio 2005,2008,2010,2012 Like that Below

Next -  want to Delete or Set Primary Key or New column Name Add
But Datatype Varchar(50) is Common for All  
Varchar want increase Varchar(100)or Varchar(200) or Varchar(MAX) 
Allow Null Values Remove

Same For All Visual Studio 2005,2008,2010,2012 Like that Below

  Next -  Sql Connection 

Go to - Design Page register.aspx and Select -ToolBox - Select Data - Select SqlDataSource -Double Click Show Like That  Below

If  Did't Show SqlDataSource in Data use Below

Right Click  - Select - Choose Items Select  Required Tools Select like that Below

Required tools Selected After  Click - OK Button Selected Files Show ToolBox

Next -  Click SqlDataSource Aero (>) Mark Click Show  Configuration Data Source and Click

Next  - Select Database.mdf  like that below

Next - Click -  Next Button   

Next - Click - Next - Button Press

 Next - Select  Table Name register  and * Select and Press  - Next Button

Next - Register.aspx Page  Select SqlDataSource   
and  F4 press  Property Window Open Connected Path Like that  Below

Next - Go To - Solution Explore - Click Web.Config - Change Name From connection String  to Dbcon

 Change the  Name 

After Change Name  Save and Close Web.config  Go To Design Page register.aspx  

Change the Name from connectionString to dbcon ( if your choice dbcon or else)

Next - Save and  Go - To Register.aspx   and  Double Click Register Button Like That Below

Next - Add -  NameSpaces for Library Function Calls Like that below

using // access Datatable and Dataset 
using  // access Sqlconnnection & sqlCommand

Next - Create - Database Connection Publically

 SqlCommand cmd;    // Create object  for calling 
    SqlConnection con;  // Create object  for calling 
    SqlDataAdapter adp;     // Create object  for calling 
    DataTable dt;   // Create object  for calling 
    DataSet ds;     // Create object  for calling 

    string query;     // Assign String Variable

Next - Insert Values to Database Table  

Go to - Register.aspx page  and then Double Click Register Button 

Next -  Coding For Insert Command 

Above give the TextBox Id Name  now Go To Register.aspx page  give is name to TextBox

Now Change the Textbox Id  to your Identification  like that below

Same as all Textbox  like that Below 

Next -  Go to - Coding Part register.aspx.cs    

Given Insert  Coding  Completely

Next  - Go To - register.aspx

Next  - Run the Program  to Press  F5 or  internet Explorer  or Google Chrome (your default Browser)

Press - Ok - button  Go To Browser (your PC Default Browser) 


Enter Values &  Register Button Click

Next -  Register Button Click

IF Program without Error  Pop Up Display 

 IF Error Occurred Show Like that below Clear the Error

Next - Go To  Coding Page register.aspx.cs 

 Clear the Error 

Same  Id Given Clear  Below

Correct Order given to Id  and Column Name
  txtName.Text &  txtMobile.Text & txtemail.Text       Importants

After clear the Error  Run The Program Click F5 or Google Chrome

Display   POP UP 

Show the Data Go to Database - Right Click - Table Show Table Data

Next - Close  Register Table  Go To Add New Form   

After Show Solution Explorer Display.aspx 

Next - Select Tool Box Add  Button to Display Registered Data's 

Go To  Data-Select Data Grid View Select 

Button Name Change to F4 Press - Property Windows open - Text Change to Dispaly 

Display Button Double Click  & Give Coding

Common For All Form Above DataBase Connection

And  Select command Coding Below

Next -  Run the Program  Press F5

Click the Display Button Show the Data's Grid View

Error occurred  Table Name  Not Correctly  given 

Give the Correct  Name

Run   & display button Click Show the Output

Next  - Update  the Already Inserted Data's

Register.aspx  Form Uses Update Button add

Double Click  - Update Button  - Write Coding

Run the  Program    

Insert values to TextBox   and Update Button Click

Updated  Values  Display  Display.aspx Form

Changed  abcd Name  mobile number & email Id

Delete  Table 

Next - Delete Particular  Table Name  from Register.aspx Form 

Go To - Coding Part Double Click  Delete Button 

Run the Program  to Delete  

Give column name only Delete  Particular Data

Delete Button Click Delete Values 

Next - Display.aspx Run


Post a Comment