E
Electric Co.
Hello,
I am newbie to the group so hi all! My name is Jim and I am a
codaholic. Ok so now that is out of the way.
I am new to using all things static and I am wondering if what I am
doing is going to get me in trouble.
I am using the component designer to build my Sql Server objects for
me. I then expose methods such as getDataSet as static methods. In
order to leverage the non-static properties that the designer creates
for me I instantiate a new object of the component designer and set its
properties accordingly (mainly the SqlServer connection on the command
objects so that each Sql server command has its own connection).
One thing of note:
1.) Private methods are exposed to the New Instance of the component
designer inside of the static method. (Makes me a bit concerned that
something funny is going on)
The code below gives an example.
using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;
using System.Data.SqlClient;
namespace GoDAT.Venue
{
public class Venue : System.ComponentModel.Component
{
// ~~~~
// ~~~~
#region CONSTRUCTOR
public Venue(System.ComponentModel.IContainer container)
{
container.Add(this);
InitializeComponent();
}
public Venue()
{
InitializeComponent();
}
#endregion
// ~~~~
// ~~~~
// ~~~~
// ~~
#region DISPOSAL
protected override void Dispose( bool disposing )
{
//blah, blah, blah
}
#endregion
private System.Data.SqlClient.SqlCommand sqlSelect_Venue;
private System.Data.SqlClient.SqlCommand sqlInsert_Venue;
private System.Data.SqlClient.SqlCommand sqlUpdate_Venue;
private System.Data.SqlClient.SqlCommand sqlDelete_Venue;
private System.Data.SqlClient.SqlDataAdapter sqlDA_Venue;
private GoDAT.Venue.dsVenue dsVenue1;
// ~~~~~
// ~~~~~
// ~~~~
// ~~~~
#region Component Designer generated code
// ALL THAT GREAT CODE GENERATED FOR FREE!!!!
// Or rather for the price of VS.NET and the
// hours of trial and error trying to figure
// out how to best leverage it.
#endregion
// ~~~~
// ~~~~
// ~~~~
public static GoDAT.Venue.dsVenue Get_dsVenue()
{
Venue tmpThis = new Venue();
GoDAT.Venue.dsVenue tmpDS = tmpThis.dsVenue1;
SqlDataAdapter adapter = tmpThis.sqlDA_Venue;
tmpThis.sqlSelect_Venue.Connection = SQLConnMgr.GetSqlConn();
tmpThis.sqlSelect_Venue.Connection.Open();
try
{
adapter.Fill(tmpDS);
}
catch (Exception e)
{
System.Diagnostics.Trace.WriteLine(("[Get_dsVenue] Exception " +
e.Message));
}
finally
{
adapter.Dispose();
tmpThis.sqlSelect_Venue.Connection.Close();
tmpThis.sqlSelect_Venue.Connection = null;
tmpThis = null;
}
return tmpDS;
}
// ~~~~~
}
}
I am newbie to the group so hi all! My name is Jim and I am a
codaholic. Ok so now that is out of the way.
I am new to using all things static and I am wondering if what I am
doing is going to get me in trouble.
I am using the component designer to build my Sql Server objects for
me. I then expose methods such as getDataSet as static methods. In
order to leverage the non-static properties that the designer creates
for me I instantiate a new object of the component designer and set its
properties accordingly (mainly the SqlServer connection on the command
objects so that each Sql server command has its own connection).
One thing of note:
1.) Private methods are exposed to the New Instance of the component
designer inside of the static method. (Makes me a bit concerned that
something funny is going on)
The code below gives an example.
using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;
using System.Data.SqlClient;
namespace GoDAT.Venue
{
public class Venue : System.ComponentModel.Component
{
// ~~~~
// ~~~~
#region CONSTRUCTOR
public Venue(System.ComponentModel.IContainer container)
{
container.Add(this);
InitializeComponent();
}
public Venue()
{
InitializeComponent();
}
#endregion
// ~~~~
// ~~~~
// ~~~~
// ~~
#region DISPOSAL
protected override void Dispose( bool disposing )
{
//blah, blah, blah
}
#endregion
private System.Data.SqlClient.SqlCommand sqlSelect_Venue;
private System.Data.SqlClient.SqlCommand sqlInsert_Venue;
private System.Data.SqlClient.SqlCommand sqlUpdate_Venue;
private System.Data.SqlClient.SqlCommand sqlDelete_Venue;
private System.Data.SqlClient.SqlDataAdapter sqlDA_Venue;
private GoDAT.Venue.dsVenue dsVenue1;
// ~~~~~
// ~~~~~
// ~~~~
// ~~~~
#region Component Designer generated code
// ALL THAT GREAT CODE GENERATED FOR FREE!!!!
// Or rather for the price of VS.NET and the
// hours of trial and error trying to figure
// out how to best leverage it.
#endregion
// ~~~~
// ~~~~
// ~~~~
public static GoDAT.Venue.dsVenue Get_dsVenue()
{
Venue tmpThis = new Venue();
GoDAT.Venue.dsVenue tmpDS = tmpThis.dsVenue1;
SqlDataAdapter adapter = tmpThis.sqlDA_Venue;
tmpThis.sqlSelect_Venue.Connection = SQLConnMgr.GetSqlConn();
tmpThis.sqlSelect_Venue.Connection.Open();
try
{
adapter.Fill(tmpDS);
}
catch (Exception e)
{
System.Diagnostics.Trace.WriteLine(("[Get_dsVenue] Exception " +
e.Message));
}
finally
{
adapter.Dispose();
tmpThis.sqlSelect_Venue.Connection.Close();
tmpThis.sqlSelect_Venue.Connection = null;
tmpThis = null;
}
return tmpDS;
}
// ~~~~~
}
}