参数化查询,但未提供该参数。 50
namespaceDataAccess{publicclassDA{staticDA(){conn=newSqlConnection(@"server=.\sqlexpr...
namespace DataAccess{ public class DA { static DA() { conn = new SqlConnection(@"server=.\sqlexpress;database=govDB;integrated security=sspi"); cmd = new SqlCommand(); cmd.Connection = conn; } public static int ExcuteSql(string sqlText, CommandType commandType, string[] paraNmes, object[] paraValues) { if (conn.State != ConnectionState.Open) { conn.Open(); } cmd.CommandText = sqlText; cmd.CommandType = commandType; if (paraNmes != null) { for (int i = 0; i < paraNmes.Length; i++) { cmd.Parameters.AddWithValue(paraNmes[i], paraValues[i]); } } int count = cmd.ExecuteNonQuery(); cmd.Parameters.Clear(); conn.Close(); return count; }
namespace Business
{
public class OfficerBusiness { public int InsertOfficer(OfficerEntity oe) { string sqlText = "insert into tb_officer values(@oname,@ophoto,@omess,@oworkfor)"; string[] paraNames = {"@oname","@ophoto","@omess","@oworkfor" }; object[] paraValues = {oe.Oname,oe.Ophoto,oe.Omess,oe.Oworkfor }; int count = DA.ExcuteSql(sqlText,CommandType.Text,paraNames,paraValues); return count; } 展开
namespace Business
{
public class OfficerBusiness { public int InsertOfficer(OfficerEntity oe) { string sqlText = "insert into tb_officer values(@oname,@ophoto,@omess,@oworkfor)"; string[] paraNames = {"@oname","@ophoto","@omess","@oworkfor" }; object[] paraValues = {oe.Oname,oe.Ophoto,oe.Omess,oe.Oworkfor }; int count = DA.ExcuteSql(sqlText,CommandType.Text,paraNames,paraValues); return count; } 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询