srujana thallam

srujana thallam

  • NA
  • 76
  • 138.7k

GettingConnection using SQL in CSharp

Dec 5 2013 10:23 AM
 I want to generalise the getting connection for that I write a method in C# Class file like this

 public SqlConnection GetConnection(SqlConnection objSqlCon)
  {
  SqlConnection con = new SqlConnection();
  try
  {
  objSqlCon.ConnectionString = con.ConnectionString();
  objSqlCon.Open();
  return objSqlCon;
  } 
  catch(Exception e)
  {
  }
  }

it shows an error like this
  'System.Data.SqlClient.SqlConnection.ConnectionString' is a 'property' but is used like a 'method' 

or else can u please tell me the another way to get connection by passing sqlconnection  to that method.

Thanks in Advance.


Answers (3)