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\c lConnect.cs(18) :
'connect_class. clConnect.Creat eDataset(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.Sql Client;
using System.Data;
namespace connect_class
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class clConnect
{
public clConnect()
{
}
// Create dataset
public DataSet CreateDataset(s tring sSQL)
{
string sConn="Data Source=Win2000; Initial Catalog=CustSer v;User
ID=mlut2;Passwo rd=dk%$one22";
SqlConnection Con = new SqlConnection() ;
SqlCommand Cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter( );
DataSet ds = new DataSet("Report ");
try
{
Cmd.CommandType =CommandType.Te xt;
Cmd.CommandText =sSQL;
Cmd.Connection= Con;
Cmd.CommandTime out=480;
da.SelectComman d=Cmd;
Con.ConnectionS tring=sConn;
Con.Open();
da.Fill(ds);
return ds;
}
catch(System.Ex ception)
{
}
finally
{
if (Con !=null)
Con.Close();
if (Cmd !=null)
Cmd.Dispose();
if (da !=null)
da.Dispose();
}
}
}
}
Thank you,
--
Peter Afonin
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\c lConnect.cs(18) :
'connect_class. clConnect.Creat eDataset(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.Sql Client;
using System.Data;
namespace connect_class
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class clConnect
{
public clConnect()
{
}
// Create dataset
public DataSet CreateDataset(s tring sSQL)
{
string sConn="Data Source=Win2000; Initial Catalog=CustSer v;User
ID=mlut2;Passwo rd=dk%$one22";
SqlConnection Con = new SqlConnection() ;
SqlCommand Cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter( );
DataSet ds = new DataSet("Report ");
try
{
Cmd.CommandType =CommandType.Te xt;
Cmd.CommandText =sSQL;
Cmd.Connection= Con;
Cmd.CommandTime out=480;
da.SelectComman d=Cmd;
Con.ConnectionS tring=sConn;
Con.Open();
da.Fill(ds);
return ds;
}
catch(System.Ex ception)
{
}
finally
{
if (Con !=null)
Con.Close();
if (Cmd !=null)
Cmd.Dispose();
if (da !=null)
da.Dispose();
}
}
}
}
Thank you,
--
Peter Afonin
Comment