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.
Loading
Jignesh TrivediPosted Dec 5, 2013, 11:18 PM
hi,
ConnectionString is property of connection object not method,
so remove braket from end..
try...
public SqlConnection GetConnection(SqlConnection objSqlCon)
{
SqlConnection con = new SqlConnection();
try
{
objSqlCon.ConnectionString = con.ConnectionString;
objSqlCon.Open();
return objSqlCon;
}
catch (Exception e)
{
return null;
}
}
hope this will help you.
srujana thallamPosted Dec 5, 2013, 11:57 AM
But I want to create a method like when ever i want to open a connection i just call this method by passing connection like this am expecting.
Abhay ShankerPosted Dec 5, 2013, 11:52 AM