curiouswebster
asked on
Need to convert from OleDb to SQL Express format
Hi,
Is there an easy way to reformat this code which I use with Microsoft Access to use SQL Express instead?
I do remember there being calls which are in common.
Could someone take a shot at it?
thanks,
newbiewb
public void SynchronizeID()
{
OleDbConnection conn = null;
OleDbCommand dbSelectCommand = null;
OleDbDataReader reader = null;
string sql = null;
try
{
conn = new OleDbConnection();
conn.ConnectionString = Handles.Preferences.DMSCon nectionStr ing;
conn.Open();
dbSelectCommand = new OleDbCommand();
dbSelectCommand.Connection = conn;
sql = "SELECT ID FROM BadgeIDs WHERE BadgeID='" + badgeID + "'";
dbSelectCommand.CommandTex t = sql;
reader = dbSelectCommand.ExecuteRea der();
if ( reader.Read() )
{
this.id = reader.GetInt32(0);
}
}
catch (Exception ex)
{
Handles.LogException( "TLLocation.SynchronizeID( )", ex, sql );
}
finally
{
if ( reader != null )
reader.Close();
if ( dbSelectCommand != null )
dbSelectCommand.Dispose();
if ( conn != null )
{
conn.Close();
conn.Dispose();
}
}
}
Is there an easy way to reformat this code which I use with Microsoft Access to use SQL Express instead?
I do remember there being calls which are in common.
Could someone take a shot at it?
thanks,
newbiewb
public void SynchronizeID()
{
OleDbConnection conn = null;
OleDbCommand dbSelectCommand = null;
OleDbDataReader reader = null;
string sql = null;
try
{
conn = new OleDbConnection();
conn.ConnectionString = Handles.Preferences.DMSCon
conn.Open();
dbSelectCommand = new OleDbCommand();
dbSelectCommand.Connection
sql = "SELECT ID FROM BadgeIDs WHERE BadgeID='" + badgeID + "'";
dbSelectCommand.CommandTex
reader = dbSelectCommand.ExecuteRea
if ( reader.Read() )
{
this.id = reader.GetInt32(0);
}
}
catch (Exception ex)
{
Handles.LogException( "TLLocation.SynchronizeID(
}
finally
{
if ( reader != null )
reader.Close();
if ( dbSelectCommand != null )
dbSelectCommand.Dispose();
if ( conn != null )
{
conn.Close();
conn.Dispose();
}
}
}
and of course you need to add
using System.Data.SqlClient;
using System.Data.SqlClient;
ASKER
something's not right.
The compiler can not find anything starting with Sql.
SQLDbConnection or SqlDbConnection or any of the others.
and the help has nothing on any of them.
Are you sure System.Data.SqlClient is the only thing I need?
The compiler can not find anything starting with Sql.
SQLDbConnection or SqlDbConnection or any of the others.
and the help has nothing on any of them.
Are you sure System.Data.SqlClient is the only thing I need?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
public void SynchronizeID()
{
SqlDbConnection conn = null;
SqlDbCommand dbSelectCommand = null;
SqlDbDataReader reader = null;
string sql = null;
try
{
conn = new SqlDbConnection();
conn.ConnectionString = Handles.Preferences.DMSCon
conn.Open();
dbSelectCommand = new SqlDbCommand();
dbSelectCommand.Connection
sql = "SELECT ID FROM BadgeIDs WHERE BadgeID='" + badgeID + "'";
dbSelectCommand.CommandTex
reader = dbSelectCommand.ExecuteRea
if ( reader.Read() )
{
this.id = reader.GetInt32(0);
}
}
catch (Exception ex)
{
Handles.LogException( "TLLocation.SynchronizeID(
}
finally
{
if ( reader != null )
reader.Close();
if ( dbSelectCommand != null )
dbSelectCommand.Dispose();
if ( conn != null )
{
conn.Close();
conn.Dispose();
}
}
}