He's not right, he can never be right. :bigyello:
Just use something like
VB Code:
void NonQuery(string cmdtext,
sql.Parameters param)
{
try
{
sql.Connection.Open(cn);
new sql.Command(cmdtext,cn,param).ExecuteNonQuery();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
sql.Connection.Close(cn);
}
}
where sql.Parameters is a collection of type SqlParameter, something like this
VB Code:
using System;
using System.Data.SqlClient;
using System.Collections;
namespace lguis_0_1.sql
{
public class Parameters:CollectionBase
{
public Parameters(){}
public SqlParameter this[int i]
{
get{ return (SqlParameter)this.InnerList[i];}
}
public void Add(SqlParameter v)
{
this.InnerList.Add(v);
}
}
}
and the sql.Command is something like
VB Code:
using System;
using System.Data;
using System.Data.SqlClient;
namespace lguis_0_1.sql
{
public class Command
{
SqlCommand cm=new SqlCommand();
public Command(){}
public Command(string cmdtext,
SqlConnection cn)
{
cm.CommandText=cmdtext;
cm.CommandType=CommandType.StoredProcedure;
cm.Connection=cn;
}
public Command(string cmdtext,
SqlConnection cn,
Parameters param)
{
cm.CommandText=cmdtext;
cm.CommandType=CommandType.StoredProcedure;
cm.Connection=cn;
foreach(SqlParameter t in param) cm.Parameters.Add(t);
}
public void ExecuteNonQuery()
{
cm.ExecuteNonQuery();
}
public SqlDataReader ExecuteReader()
{
return cm.ExecuteReader();
}
public object ExecuteScalar()
{
return cm.ExecuteScalar();
}
}
}
and the sql.Connection is
VB Code:
using System;
using System.Data;
using System.Data.SqlClient;
namespace lguis_0_1.sql
{
public class Connection
{
public Connection(){}
public static void Close(SqlConnection cn)
{
if(cn.State==ConnectionState.Open) cn.Close();
}
public static void Open(SqlConnection cn)
{
if(cn.State==ConnectionState.Closed) cn.Open();
}
}
}
I could be totally wrong. :bigyello: