Hii Dear,
Here i am going to tell you all how you can create a connection String using a class with C# language for a database in SQL Server 2008 Express edition,dont be panic it's so easy follow these steps:
1.Add new Item -> Select a Class(C#) -> Give a name to that Class
2.Add two NameSpaces:
using System.Data;
using System.Data.SqlClient;
3.Write code like following:
using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Data.SqlClient;
///
/// Summary description for MyConn
///
public class MyConn
{
public SqlConnection con = new SqlConnection();
public SqlCommand cmd = new SqlCommand();
public SqlDataAdapter adp = new SqlDataAdapter();
public DataSet ds = new DataSet();
public DataRow dr;
public MyConn()
{
con.ConnectionString = "Data Source=meha-pc\\sqlexpress;DataBase=dbname; user ID=abc; password=abc";
adp.SelectCommand = cmd;
cmd.Connection = con;
//
// TODO: Add constructor logic here
//
}
For connection String you can select your authentication mode as per your SQL Server Security Settings,here i select server authentication for the the databse dbname,if you select Windows authentication write "Integrated Security=true " at the place of user ID=abc; password=abc" .
-----------
Thanks
Here i am going to tell you all how you can create a connection String using a class with C# language for a database in SQL Server 2008 Express edition,dont be panic it's so easy follow these steps:
1.Add new Item -> Select a Class(C#) -> Give a name to that Class
2.Add two NameSpaces:
using System.Data;
using System.Data.SqlClient;
3.Write code like following:
using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Data.SqlClient;
///
/// Summary description for MyConn
///
public class MyConn
{
public SqlConnection con = new SqlConnection();
public SqlCommand cmd = new SqlCommand();
public SqlDataAdapter adp = new SqlDataAdapter();
public DataSet ds = new DataSet();
public DataRow dr;
public MyConn()
{
con.ConnectionString = "Data Source=meha-pc\\sqlexpress;DataBase=dbname; user ID=abc; password=abc";
adp.SelectCommand = cmd;
cmd.Connection = con;
//
// TODO: Add constructor logic here
//
}
For connection String you can select your authentication mode as per your SQL Server Security Settings,here i select server authentication for the the databse dbname,if you select Windows authentication write "Integrated Security=true " at the place of user ID=abc; password=abc" .
-----------
Thanks
No comments:
Post a Comment