SQL method taking a long time - c#

I'm using SQLite with C#.
I use the following method to loop through a list of tv shows and their episodes and insert them into the database. It ends up entering about 1200 rows and takes 2 minutes 28 seconds. It feels like that's kinda slow so I would like people to look over my method and see if i'm doing something stupid (I'm sorta new to this).
public void InsertAllEpisodes(List<TVDBSharp.Models.Show> showList)
{
using (SQLiteConnection dbconnection = new SQLiteConnection(connectionString))
{
string seasonNumber;
string episodeNumber;
string insertShowSQL = #"INSERT INTO AllEpisodes (Key, ShowName, ShowId, EpisodeName, SeasonEpisode) VALUES (#Key, #ShowName, #ShowId, #EpisodeName, #SeasonEpisode)";
foreach (var show in showList)
{
foreach (var episode in show.Episodes)
{
if (episode.SeasonNumber != 0)
{
string seasonEpisode = "default";
if ((episode.SeasonNumber != 0) && (episode.SeasonNumber.ToString().Length == 1)) { seasonNumber = "0" + episode.SeasonNumber.ToString(); }
else { seasonNumber = episode.SeasonNumber.ToString(); }
if (episode.EpisodeNumber.ToString().Length == 1) { episodeNumber = "0" + episode.EpisodeNumber.ToString(); }
else { episodeNumber = episode.EpisodeNumber.ToString(); }
seasonEpisode = seasonNumber + episodeNumber;
SQLiteCommand command = new SQLiteCommand(insertShowSQL, dbconnection);
command.Parameters.AddWithValue("Key", show.Id + seasonEpisode);
command.Parameters.AddWithValue("ShowName", show.Name);
command.Parameters.AddWithValue("ShowId", show.Id);
command.Parameters.AddWithValue("EpisodeName", episode.Title);
command.Parameters.AddWithValue("SeasonEpisode", seasonEpisode);
dbconnection.Open();
try
{
command.ExecuteScalar();
}
catch (SQLiteException ex)
{
if (ex.ResultCode != SQLiteErrorCode.Constraint)
{
File.AppendAllText(programDataPath + "SQLErrors.txt", ex.Message + "\n");
}
}
dbconnection.Close();
}
}
}
}
}

I read up on and used sqlComm = new SQLiteCommand("begin", dbconnection) and sqlComm = new SQLiteCommand("end", dbconnection) and it inserted it in less than 1 second.
public void InsertAllEpisodes(List<TVDBSharp.Models.Show> showList)
{
using (SQLiteConnection dbconnection = new SQLiteConnection(connectionString))
{
dbconnection.Open();
string seasonNumber;
string episodeNumber;
string insertShowSQL = #"INSERT INTO AllEpisodes (Key, ShowName, ShowId, EpisodeName, SeasonEpisode) VALUES (#Key, #ShowName, #ShowId, #EpisodeName, #SeasonEpisode)";
SQLiteCommand sqlComm;
sqlComm = new SQLiteCommand("begin", dbconnection);
sqlComm.ExecuteNonQuery();
foreach (var show in showList)
{
foreach (var episode in show.Episodes)
{
if (episode.SeasonNumber != 0)
{
string seasonEpisode = "default";
if ((episode.SeasonNumber != 0) && (episode.SeasonNumber.ToString().Length == 1)) { seasonNumber = "0" + episode.SeasonNumber.ToString(); }
else { seasonNumber = episode.SeasonNumber.ToString(); }
if (episode.EpisodeNumber.ToString().Length == 1) { episodeNumber = "0" + episode.EpisodeNumber.ToString(); }
else { episodeNumber = episode.EpisodeNumber.ToString(); }
seasonEpisode = seasonNumber + episodeNumber;
sqlComm = new SQLiteCommand(insertShowSQL, dbconnection);
sqlComm.Parameters.AddWithValue("Key", show.Id + seasonEpisode);
sqlComm.Parameters.AddWithValue("ShowName", show.Name);
sqlComm.Parameters.AddWithValue("ShowId", show.Id);
sqlComm.Parameters.AddWithValue("EpisodeName", episode.Title);
sqlComm.Parameters.AddWithValue("SeasonEpisode", seasonEpisode);
try
{
sqlComm.ExecuteScalar();
}
catch (SQLiteException ex)
{
if (ex.ResultCode != SQLiteErrorCode.Constraint)
{
File.AppendAllText(programDataPath + "SQLErrors.txt", ex.Message + "\n");
}
}
}
}
}
sqlComm = new SQLiteCommand("end", dbconnection);
sqlComm.ExecuteNonQuery();
dbconnection.Close();
}
}

Related

IC# - Im getting "The Connection is open" MYSQL database

I am doing a college attendance project with Winforms, MySQL, and C#.
In that I want to get or add "Users". So I wrote code for that:
public bool GetUser(ref clsConnection c)
{
MySqlCommand query = new MySqlCommand();
query.Connection = SQL;
query.CommandText = "SELECT ";
foreach (FieldInfo mi in typeof(clsConnection).GetFields())
{
foreach (StatsAttribute a in mi.GetCustomAttributes(typeof(StatsAttribute), false))
{
query.CommandText += a.Name + ", ";
}
}
query.CommandText = query.CommandText.Substring(0, query.CommandText.Length - 2);
query.CommandText += " FROM user WHERE User_Name='" + Escape(c.Username) + "'";
query.Prepare();
MySqlDataReader dr = query.ExecuteReader();
if (dr.HasRows)
{
foreach (FieldInfo mi in typeof(clsConnection).GetFields())
{
foreach (StatsAttribute a in mi.GetCustomAttributes(typeof(StatsAttribute), false))
{
dr.Read();
if (mi.FieldType.Name == "String")
{
mi.SetValue(c, (object)dr.GetString(a.Name));
}
else if (mi.FieldType.Name == "Double")
{
mi.SetValue(c, (object)dr.GetDouble(a.Name));
}
else if (mi.FieldType.Name == "Int32")
{
mi.SetValue(c, (object)dr.GetInt32(a.Name));
}
else if (mi.FieldType.Name == "UInt32")
{
mi.SetValue(c, (object)dr.GetUInt32(a.Name));
}
else if (mi.FieldType.Name == "Byte")
{
mi.SetValue(c, (object)dr.GetByte(a.Name));
}
else if (mi.FieldType.Name == "Boolean")
{
mi.SetValue(c, (object)dr.GetBoolean(a.Name));
}
else if (mi.FieldType.Name == "Date")
{
mi.SetValue(c, (object)dr.GetDateTime(a.Name));
}
}
}
}
else
{
dr.Close();
return false;
}
dr.Close();
return true;
}
public void AddUser(clsConnection c)
{
if (c.Username == "")
return;
List<string> users = new List<string>();
List<string> values = new List<string>();
int i = 0;
foreach (FieldInfo mi in typeof(clsConnection).GetFields())
{
foreach (StatsAttribute a in mi.GetCustomAttributes(typeof(StatsAttribute), false))
{
users.Add(a.Name);
values.Add("'" + mi.GetValue(c) + "'");
i++;
}
}
string query = "INSERT INTO user(" + string.Join(",", users.ToArray()) + ") VALUES (" + string.Join(",", values.ToArray()) + ");";
Query(query);
}
Im getting error with "The connection is open" when i try to connect with new or exist account. I can't find where is my problem... Probable somewhere is getuser or newuser im not closing data reader, but can't find where, please help me...
I am not sure if you close the connection here. Try with adding this after closing the "MySqlDataReader".
query.Connection.Close();
Also, you can see below an example;
https://dev.mysql.com/doc/dev/connector-net/8.0/html/M_MySql_Data_MySqlClient_MySqlCommand_ExecuteReader.htm

Prevent duplicates in datagrid when databound

after some testing I came with this way to handle my datagrid. dgVariedad_CellEditEnding use the function nombreVariedadDisponible(txtBoxTemporal.Text) to check if the new value already exist in List<Variedad> variedades and it works. The problem is that the value wont be inserted in the database but will be added in the datagrid control, I can't find a way to cancel the new row in the control.
private List<Variedad> variedades = new List<Variedad>();
private void bindVariedad()
{
using (MySqlCommand cmd = Conexion.con.CreateCommand())
{
cmd.CommandText = "SELECT NOMBRE FROM DATAFRUT_VARIEDADES WHERE ELIMINADO = 'F';";
Conexion.abrirConexion();
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataTable table = new DataTable("DATAFRUT_VARIEDADES");
da.Fill(table);
table.Columns[0].ColumnName = "Nombre";
dgVariedad.ItemsSource = table.DefaultView;
cmd.CommandText = "SELECT * FROM DATAFRUT_VARIEDADES WHERE ELIMINADO = 'F';";
using (MySqlDataReader dr = cmd.ExecuteReader())
{
variedades.Clear();
while (dr.Read())
{
Variedad var = new Variedad();
var.codigo = Convert.ToInt32(dr[0]);
var.nombre = dr[1].ToString();
var.eliminado = Convert.ToChar(dr[2]);
variedades.Add(var);
}
}
}
}
private void dgVariedad_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
TextBox txtBoxTemporal = e.EditingElement as TextBox;
int indice = e.Row.GetIndex();
if (e.Row.IsNewItem)
{
if (nombreVariedadDisponible(txtBoxTemporal.Text))
{
bool insertExitoso = false;
using (MySqlCommand cmd = Conexion.con.CreateCommand())
{
Conexion.abrirConexion();
cmd.CommandText = "INSERT INTO DATAFRUT_VARIEDADES VALUES (default, '" + txtBoxTemporal.Text + "', 'F');";
try
{
cmd.ExecuteNonQuery();
insertExitoso = true;
}
catch
{
MessageBox.Show("Error");
}
Conexion.cerrarConexion();
}
if (insertExitoso)
{
variedades.Add(Variedad.cargarUltimoInsert(txtBoxTemporal.Text));
}
}
else
{
e.Cancel = true;
}
}
else
{
using (MySqlCommand cmd = Conexion.con.CreateCommand())
{
Conexion.abrirConexion();
DataRowView dataRow = (DataRowView)dgVariedad.SelectedItem;
cmd.CommandText = "UPDATE DATAFRUT_VARIEDADES SET NOMBRE = '" + txtBoxTemporal.Text + "' WHERE CODIGO = " + variedades[dgVariedad.SelectedIndex].codigo + ";";
try
{
cmd.ExecuteNonQuery();
variedades[dgVariedad.SelectedIndex].nombre = txtBoxTemporal.Text;
}
catch(MySqlException mex)
{
MessageBox.Show("Error " + mex.Message);
}
Conexion.cerrarConexion();
}
}
}
My table on mysql has 3 fields:
int codigo (primary key, auto increment)
string Nombre (Unique) char
char Eliminado -> Eliminado (Deleted) with values (F = false and V =
true)
Here is how I check if the value already exist.
private bool nombreVariedadDisponible(string nombreAComparar)
{
//busca el nombre en la lista "variedades"
foreach (Variedad var in variedades)
{
if (var.nombre.ToLower() == nombreAComparar.ToLower() && var.eliminado == 'F')
return false;
}
return true;
}

How can i log SqlCommand queries to analyze at SQL server tuning advisor

I have a DB connection class which executes all of my DB connections
I want to capture the queries and run them on SQL server tuning advisor to find out missing indexes etc
The SQL server profiler tuning takes forever to process. So i want to compose my own file to analyze
The issue is i don't know how should i capture query to properly analyze
Here my SqlCommand function
SQL server 2014 , c# .net 4.5
My question is what parameters, values etc i should log to analyze them perfectly
public static DataTable cmd_SelectQuery(string srCommandText, List<string> lstParameterNames, List<object> lstParameters)
{
DataTable dsCmdPara = new DataTable();
try
{
using (SqlConnection connection = new SqlConnection(DbConnection.srConnectionString))
{
using (SqlCommand cmd = new SqlCommand(srCommandText, connection))
{
cmd.CommandTimeout = PublicSettings.irCommandTimeOutSettings_Second;
cmd.CommandType = CommandType.Text;
object objParameter;
for (int i = 0; i < lstParameterNames.Count; i++)
{
objParameter = lstParameters[i];
if (objParameter == null)
objParameter = "n";
cmd.Parameters.AddWithValue(lstParameterNames[i], lstParameters[i].ToString());
}
using (SqlDataAdapter sqlDa = new SqlDataAdapter(cmd))
{
sqlDa.Fill(dsCmdPara);
return dsCmdPara;
}
}
}
}
catch (Exception E)
{
Interlocked.Increment(ref GlobalStats.long_GlobalSQLErrorCount);
StringBuilder srParameters = new StringBuilder();
if (PublicSettings.blLogSqlParametersOnErrors == true)
{
srParameters.AppendLine("");
srParameters.AppendLine("error at : cmd_UpdateDeleteQuery");
foreach (var vrItem in lstParameters)
{
srParameters.AppendLine("per parameter: " + vrItem + " \r\n\r\n");
}
}
if (PublicSettings.blLogSqlErrors)
ErrorLogger.LogSQL_Error("Error at: cmd_SelectQuery " + srCommandText + " " + E.Message.ToString() + " \r\n" + srParameters.ToString());
}
return dsCmdPara;
}
public static bool cmd_UpdateDeleteQuery(string srCommandText, List<string> lstParameterNames, List<object> lstParameters)
{
try
{
using (SqlConnection connection = new SqlConnection(DbConnection.srConnectionString))
{
using (SqlCommand cmd = new SqlCommand(srCommandText, connection))
{
cmd.CommandTimeout = PublicSettings.irCommandTimeOutSettings_Second;
cmd.CommandType = CommandType.Text;
object objParameter;
for (int i = 0; i < lstParameterNames.Count; i++)
{
objParameter = lstParameters[i];
if (objParameter == null)
objParameter = "n";
cmd.Parameters.AddWithValue(lstParameterNames[i], objParameter);
}
connection.Open();
cmd.ExecuteNonQuery();
return true;
}
}
}
catch (Exception E)
{
Interlocked.Increment(ref GlobalStats.long_GlobalSQLErrorCount);
StringBuilder srParameters = new StringBuilder();
if (PublicSettings.blLogSqlParametersOnErrors == true)
{
srParameters.AppendLine("");
srParameters.AppendLine("error at : cmd_UpdateDeleteQuery");
foreach (var vrItem in lstParameters)
{
srParameters.AppendLine("per parameter: " + vrItem + " \r\n\r\n");
}
}
if (PublicSettings.blLogSqlErrors)
ErrorLogger.LogSQL_Error("Error at: cmd_UpdateDeleteQuery " + srCommandText + " " + E.Message.ToString() + srParameters.ToString());
}
return false;
}

OleDbDataReader = null

I'm currently building a program which stores messages between users in a database and returns these messages to the user when the button below gets pressed. I'm using a SQL CE database using a OleDbConnection and using a DataReader.
private void button3_Click(object sender, EventArgs e)
{
string [] lec_name = new string [10] ;
string [] content = new string [10] ;
string conn = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=C:\\Users\\Leon\\Admin.sdf";
OleDbConnection connection = new OleDbConnection(conn);
OleDbCommand command = connection.CreateCommand();
command.CommandText = "SELECT * FROM Contact_DB WHERE Student_ID =" + iD + " AND Direction = '" + "To the student" + "'";
try
{
connection.Open();
}
catch (Exception ex)
{
MessageBox.Show("" + ex.Message);
}
OleDbDataReader reader = command.ExecuteReader();
int up = 0;
int count = 0;
while (reader.Read())
{
lec_name[up] = reader["Lecturer_Name"].ToString();
content[up] = reader["Description"].ToString();
up++;
MessageBox.Show("The lecturer " + lec_name[count] + " has messaged you saying :" + "\n" + content[count]);
count++;
}
}
This code works for my Student class but when I reuse the code with minor changes within the Lecturer class the OledbDataReader says null, anyone know why?
Btw the values being returned aren't null the reader itself is null.
Below is the non working code.
private void button2_Click(object sender, EventArgs e)
{
string [] studentID = new string [10] ;
string [] content = new string [10] ;
string conn = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=C:\\Users\\Leon\\Admin.sdf";
OleDbConnection connection = new OleDbConnection(conn);
OleDbCommand command = connection.CreateCommand();
command.CommandText = "SELECT * FROM Contact_DB WHERE Lecturer_Name =" + full + " AND Direction = '" + "To the lecturer" + "'";
try
{
connection.Open();
}
catch (Exception ex)
{
MessageBox.Show("" + ex.Message);
}
OleDbDataReader reader1 = command.ExecuteReader();
int up = 0;
int count = 0;
while (reader1.Read())
{
studentID[up] = reader1["Student_ID"].ToString();
content[up] = reader1["Description"].ToString();
up++;
}
MessageBox.Show("The student " + studentID[count] + " has messaged you saying :" + "\n" +content[count]);
}
}
Using Reflector:
OleDbCommand.ExcuteReader:
public OleDbDataReader ExecuteReader(CommandBehavior behavior)
{
OleDbDataReader reader;
IntPtr ptr;
OleDbConnection.ExecutePermission.Demand();
Bid.ScopeEnter(out ptr, "<oledb.OleDbCommand.ExecuteReader|API> %d#, behavior=%d{ds.CommandBehavior}\n", this.ObjectID, (int) behavior);
try
{
this._executeQuery = true;
reader = this.ExecuteReaderInternal(behavior, "ExecuteReader");
}
finally
{
Bid.ScopeLeave(ref ptr);
}
return reader;
}
The CommandBehavior is
default.the reader returned by this.ExecuteReaderInternal()---- >
private OleDbDataReader ExecuteReaderInternal(CommandBehavior behavior, string method)
{
OleDbDataReader dataReader = null;
OleDbException previous = null;
int num2 = 0;
try
{
object obj2;
int num;
this.ValidateConnectionAndTransaction(method);
if ((CommandBehavior.SingleRow & behavior) != CommandBehavior.Default) behavior |= CommandBehavior.SingleResult;
switch (this.CommandType)
{
case ((CommandType) 0):
case CommandType.Text:
case CommandType.StoredProcedure:
num = this.ExecuteCommand(behavior, out obj2);
break;
case CommandType.TableDirect:
num = this.ExecuteTableDirect(behavior, out obj2);
break;
default:
throw ADP.InvalidCommandType(this.CommandType);
}
if (this._executeQuery)
{
try
{
dataReader = new OleDbDataReader(this._connection, this, 0, this.commandBehavior);
switch (num)
{
case 0:
dataReader.InitializeIMultipleResults(obj2);
dataReader.NextResult();
break;
case 1:
dataReader.InitializeIRowset(obj2, ChapterHandle.DB_NULL_HCHAPTER, this._recordsAffected);
dataReader.BuildMetaInfo();
dataReader.HasRowsRead();
break;
case 2:
dataReader.InitializeIRow(obj2, this._recordsAffected);
dataReader.BuildMetaInfo();
break;
case 3:
if (!this._isPrepared) this.PrepareCommandText(2);
OleDbDataReader.GenerateSchemaTable(dataReader, this._icommandText, behavior);
break;
}
obj2 = null;
this._hasDataReader = true;
this._connection.AddWeakReference(dataReader, 2);
num2 = 1;
return dataReader;
}
finally
{
if (1 != num2)
{
this.canceling = true;
if (dataReader != null)
{
dataReader.Dispose();
dataReader = null;
}
}
}
}
try
{
if (num == 0)
{
UnsafeNativeMethods.IMultipleResults imultipleResults = (UnsafeNativeMethods.IMultipleResults) obj2;
previous = OleDbDataReader.NextResults(imultipleResults, this._connection, this, out this._recordsAffected);
}
}
finally
{
try
{
if (obj2 != null)
{
Marshal.ReleaseComObject(obj2);
obj2 = null;
}
this.CloseFromDataReader(this.ParameterBindings);
}
catch (Exception exception3)
{
if (!ADP.IsCatchableExceptionType(exception3)) throw;
if (previous == null) throw;
previous = new OleDbException(previous, exception3);
}
}
}
finally
{
try
{
if (dataReader == null && 1 != num2) this.ParameterCleanup();
}
catch (Exception exception2)
{
if (!ADP.IsCatchableExceptionType(exception2)) throw;
if (previous == null) throw;
previous = new OleDbException(previous, exception2);
}
if (previous != null) throw previous;
}
return dataReader;
}
this._executeQuery wraps the new instance of OleDbDataReader, if it doesn't run the dataReader will be null.
The only way the reader is returned as null is if the internal RunExecuteReader method is passed 'false' for returnStream, which it isn't.
Here is the only place where this._executeQuery is set to false, but this one is not called in parallel because of Bid.ScopeEnter and Bid.ScopeLeave.
public override int ExecuteNonQuery()
{
int num;
IntPtr ptr;
OleDbConnection.ExecutePermission.Demand();
Bid.ScopeEnter(out ptr, "<oledb.OleDbCommand.ExecuteNonQuery|API> %d#\n", this.ObjectID);
try
{
this._executeQuery = false;
this.ExecuteReaderInternal(CommandBehavior.Default, "ExecuteNonQuery");
num = ADP.IntPtrToInt32(this._recordsAffected);
}
finally
{
Bid.ScopeLeave(ref ptr);
}
return num;
}
Theoretically the data reader can be null if the query cannot be executed.
UPDATE:
https://github.com/Microsoft/referencesource/blob/master/System.Data/System/Data/OleDb/OleDbCommand.cs#L658

Can any one tell whats' wrong in my transaction

Hi all i have written the following transaction to insert data but when i am getting an exception only the data which got the exception not inserting to db the remaining all are inserting
This is what i wrote
public bool addWhole(SqlTransaction osqlTrans)
{
m_flag = false;
osqlTrans = null;
SqlConnection osqlCon = new SqlConnection(constr);
if (osqlCon.State != ConnectionState.Open)
{
osqlCon.Open();
}
osqlTrans = osqlCon.BeginTransaction();
try
{
if (this.addRisk(osqlTrans, osqlCon))
{
if (this.addEconomical(osqlTrans, osqlCon))
{
osqlTrans.Commit();
}
}
}
catch (Exception ex)
{
osqlTrans.Rollback();
}
finally
{
osqlCon.Close();
}
return m_flag;
}
public bool addRisk(SqlTransaction oRiskTrans, SqlConnection oRiskConn)
{
con = new SqlConnection(constr);
if (con.State != ConnectionState.Open)
{
con.Open();
}
cmd = new SqlCommand("insert into tblEnrollmentData (EID,Eyear,Epercent) values('" + id + "','" + str + "','" + dbPercent + "')", con); //Even i tried adding transaction in command statement
if (cmd.ExecuteNonQuery() > 0)
{
m_flag = true;
}
}
public bool addEconomical(SqlTransaction oRiskTrans, SqlConnection oRiskConn)
{
con = new SqlConnection(constr);
if (con.State != ConnectionState.Open)
{
con.Open();
}
cmd = new SqlCommand("insert into tblEnrollmentData (EID,Eyear,Epercent) values('" + id + "','" + str + "','" + dbPercent + "')", con);//Even i tried adding transaction in command statement
if (cmd.ExecuteNonQuery() > 0)
{
m_flag = true;
}
}
I tried to rollback the transaction by failing the second condition but my first statement is inserting to DB.. What should i do in order to overcome this
I'm guessing its one of these things
1) You are not using the same connection object for all the different commands
2) You are not assigning the transaction to the commands before you execute them
3) Both perhaps
Try using the same connection object and assigning the transaction to the command before you execute it for an example see this page on MSDN. http://msdn.microsoft.com/en-us/library/86773566.aspx
Transaction is not shared between connections and you always create a new connection. Use oRiskConn specified as 2nd parameter of your methods.
As you are creating a new connection in every function your code didn't work. Just remove the connection
`con = new SqlConnection(constr);`
Replace it with the connection available in your function i.e
oRiskConn and don't initialize it as a new connection. If you did so again your transaction as per your requirement will not work. Also include oRiskTrans in your command object. Then it will works as per your requirement
I don't know what some of your parameters are but it looks like you want something like this:
class SomeClass
{
// These need to be set to appropriate values
int id, str;
double dbPercent;
string constr;
public bool addWhole()
{
var m_flag = false;
using (var osqlCon = new SqlConnection(constr))
{
if (osqlCon.State != ConnectionState.Open)
{
osqlCon.Open();
}
using (var osqlTrans = osqlCon.BeginTransaction())
{
try
{
if (m_flag = this.addRisk(osqlTrans))
{
if (m_flag = this.addEconomical(osqlTrans))
{
osqlTrans.Commit();
}
}
}
catch (Exception)
{
// Use $exception in watch window if you are debugging
osqlTrans.Rollback();
}
}
}
return m_flag;
}
public bool addRisk(SqlTransaction oRiskTrans)
{
var m_flag = false;
using (var cmd = new SqlCommand("insert into tblEnrollmentData (EID,Eyear,Epercent) values('" + id + "','" + str + "','" + dbPercent + "')"))
{
cmd.Transaction = oRiskTrans;
cmd.Connection = oRiskTrans.Connection;
if (cmd.ExecuteNonQuery() > 0)
{
m_flag = true;
}
}
return m_flag;
}
public bool addEconomical(SqlTransaction oRiskTrans)
{
var m_flag = false;
using (var cmd = new SqlCommand("insert into tblEnrollmentData (EID,Eyear,Epercent) values('" + id + "','" + str + "','" + dbPercent + "')"))
{
cmd.Transaction = oRiskTrans;
cmd.Connection = oRiskTrans.Connection;
if (cmd.ExecuteNonQuery() > 0)
{
m_flag = true;
}
}
return m_flag;
}
}

Categories

Resources