P
Peter Afonin
Hello:
I'm trying to convert the connection class that I created in VB.Net for
ASP.Net application into C#. I'm doing something incorrectly, because I'm
getting the following error when trying to compile the project:
"D:\C#_Projects\connect_class\connect_class\clConnect.cs(18):
'connect_class.clConnect.CreateDataset(string)': not all code paths return a
value"
I would really appreciate if you could tell me what am I doing wrong. The
code is below.
using System;
using System.Data.SqlClient;
using System.Data;
namespace connect_class
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class clConnect
{
public clConnect()
{
}
// Create dataset
public DataSet CreateDataset(string sSQL)
{
string sConn="Data Source=Win2000;Initial Catalog=CustServ;User
ID=mlut2;Password=dk%$one22";
SqlConnection Con = new SqlConnection();
SqlCommand Cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet("Report");
try
{
Cmd.CommandType=CommandType.Text;
Cmd.CommandText=sSQL;
Cmd.Connection=Con;
Cmd.CommandTimeout=480;
da.SelectCommand=Cmd;
Con.ConnectionString=sConn;
Con.Open();
da.Fill(ds);
return ds;
}
catch(System.Exception)
{
}
finally
{
if (Con !=null)
Con.Close();
if (Cmd !=null)
Cmd.Dispose();
if (da !=null)
da.Dispose();
}
}
}
}
Thank you,
I'm trying to convert the connection class that I created in VB.Net for
ASP.Net application into C#. I'm doing something incorrectly, because I'm
getting the following error when trying to compile the project:
"D:\C#_Projects\connect_class\connect_class\clConnect.cs(18):
'connect_class.clConnect.CreateDataset(string)': not all code paths return a
value"
I would really appreciate if you could tell me what am I doing wrong. The
code is below.
using System;
using System.Data.SqlClient;
using System.Data;
namespace connect_class
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class clConnect
{
public clConnect()
{
}
// Create dataset
public DataSet CreateDataset(string sSQL)
{
string sConn="Data Source=Win2000;Initial Catalog=CustServ;User
ID=mlut2;Password=dk%$one22";
SqlConnection Con = new SqlConnection();
SqlCommand Cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet("Report");
try
{
Cmd.CommandType=CommandType.Text;
Cmd.CommandText=sSQL;
Cmd.Connection=Con;
Cmd.CommandTimeout=480;
da.SelectCommand=Cmd;
Con.ConnectionString=sConn;
Con.Open();
da.Fill(ds);
return ds;
}
catch(System.Exception)
{
}
finally
{
if (Con !=null)
Con.Close();
if (Cmd !=null)
Cmd.Dispose();
if (da !=null)
da.Dispose();
}
}
}
}
Thank you,