Knowledge Walls
Gopal Rao
Mumbai, Maharashtra, India
Create database connection in using c#
In this code i explained about how to make connection to database via c# code.
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Text;
	using System.Data.SqlClient;//need this reference to connect database
	using System.Data;//need this reference to connect database
	namespace DAL
	   public class DalViewTripDetails
	        //To refer the connection database.The below one for refer the server database.
	       // SqlConnection conn = new SqlConnection("data source=;database=DB04H12;user id=pj04h12;password=tcshyd");
	       string conn = @"Data Source=LAKSHANYA\SQLEXPRESS; Initial Catalog=master;Integrated Security=True";
	       //To refer the local windows database
	               conn.Open();//open the connection
	               SqlCommand cmd = new SqlCommand("select * from Trip_Details where userId="+user+"order by Journey_Id DESC",
	conn);//using query selecting fields from DB
	               cmd.ExecuteNonQuery();//execute the query
	           catch (Exception e)
	               throw e;
	               conn.Close();//close the connection
Previous Topics
Previous lessons of current book.
Best Lessons of ""
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details