【C# 重构】—参数化查询, 需要参数,但未提供该参数

【问题】

【原因】

出现这种错误的原因在于,在参数化查询的时候,有几个参数的值为Null,这样的话,就出现了如图所示的错误。

 

虽然参数的值就是为Null,传入数据库中就必须变成DbNull.Value

因为此null为C#的,而DbNull.Value才是数据库中的null

那为什么会报错?

因为你是传入参数,如果你给参数@cardno赋值为Null,相当于没有赋值,因为cmd.

Parameters[card].value的默认值就是Null,而不是DbNull.Value。

【解决方法】

1.添加上相应的信息,然后重新生成解决方案。

2.查看字段的名字是否和数据库相对应。

3.查看你实现的功能是否需要传参,如果是传参

如果不是传参,则是这样:

 

展开阅读全文

参数化查询但未提供参数

10-04

string sql;rn sql = "insert into jianli(username,password,name,sex,major,xueli,phone,home,jieshao,age,mail,yixiang,jingli)";rn sql += " values (@username,@password,@name,@sex,@major,@xueli,@phone,@home,@jieshao,@age,@mail,@yixiang,@jingli)";rn _cmd = new SqlCommand(sql, _cn);rn _cmd.Parameters.Add(new SqlParameter("@username",SqlDbType.NVarChar,50));rn _cmd.Parameters.Add(new SqlParameter("@password", SqlDbType.NVarChar, 50));rn _cmd.Parameters.Add(new SqlParameter("@name", SqlDbType.NVarChar, 50));rn _cmd.Parameters.Add(new SqlParameter("@sex", SqlDbType.NVarChar, 50));rn _cmd.Parameters.Add(new SqlParameter("@major", SqlDbType.NVarChar, 50));rn _cmd.Parameters.Add(new SqlParameter("@xueli", SqlDbType.NVarChar, 50));rn _cmd.Parameters.Add(new SqlParameter("@phone", SqlDbType.NVarChar, 50));rn _cmd.Parameters.Add(new SqlParameter("@home", SqlDbType.NVarChar, 50));rn _cmd.Parameters.Add(new SqlParameter("@jieshao", SqlDbType.NVarChar, 50));rn _cmd.Parameters.Add(new SqlParameter("@age", SqlDbType.NVarChar, 50));rn _cmd.Parameters.Add(new SqlParameter("@mail", SqlDbType.NVarChar, 50));rn _cmd.Parameters.Add(new SqlParameter("@yixiang", SqlDbType.NVarChar, 50));rn _cmd.Parameters.Add(new SqlParameter("@jingli", SqlDbType.NVarChar, 50));rnrn _cmd.Parameters[0].Value = user.username;rn _cmd.Parameters[1].Value = user.password;rn _cmd.Parameters[2].Value = user.name;rn _cmd.Parameters[3].Value = user.sex;rn _cmd.Parameters[4].Value = user.major;rn _cmd.Parameters[5].Value = user.xueli;rn _cmd.Parameters[6].Value = user.phone;rn _cmd.Parameters[7].Value = user.home;rn _cmd.Parameters[8].Value = user.jieshao;rn _cmd.Parameters[9].Value = user.age;rn _cmd.Parameters[10].Value = user.mail;rn _cmd.Parameters[11].Value = user.yixiang;rn _cmd.Parameters[12].Value = user.jingli; 论坛

过程需要参数但未提供参数

04-03

我用sqlhelper.cs类rn /// rn /// 执行一条返回结果集的SqlCommand命令,通过专用的连接字符串。rn /// 使用参数数组提供参数rn /// rn /// rn /// 使用示例: rn /// SqlDataReader r = ExecuteReader(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));rn /// rn /// 一个有效的数据库连接字符串rn /// SqlCommand命令类型 (存储过程, T-SQL语句, 等等。)rn /// 存储过程的名字或者 T-SQL 语句rn /// 以数组形式提供SqlCommand命令中用到的参数列表rn /// 返回一个包含结果的SqlDataReaderrn public static SqlDataReader ExecuteReader(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)rn rn SqlCommand cmd = new SqlCommand();rn SqlConnection conn = new SqlConnection(connectionString);rnrn // 在这里使用try/catch处理是因为如果方法出现异常,则SqlDataReader就不存在,rn //CommandBehavior.CloseConnection的语句就不会执行,触发的异常由catch捕获。rn //关闭数据库连接,并通过throw再次引发捕捉到的异常。rn tryrn rnrn PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);rn rn [color=#FF0000][color=#FF0000][color=#FF0000] SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior .CloseConnection );//rdr为空[/color][/color][/color] rn cmd.Parameters.Clear();rn return rdr;rn rn catchrn rn conn.Close();rn throw;rn rn finallyrn rn if (conn.State != ConnectionState.Closed) rn rn conn.Close();rn rn rn rn private static void PrepareCommand(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, CommandType cmdType, string cmdText, SqlParameter[] cmdParms)rn rnrn //判断数据库连接状态rn if (conn.State != ConnectionState.Open)rn rn conn.Open();rn rnrn cmd.Connection = conn;rn cmd.CommandText = cmdText;rnrn //判断是否需要事物处理rn if (trans != null)rn cmd.Transaction = trans;rnrn cmd.CommandType = cmdType;rnrn if (cmdParms != null)rn rn foreach (SqlParameter parm in cmdParms)rn cmd.Parameters.Add(parm);rn rn rn存储过程:rnALTER PROCEDURE Pr_GetUserLoginrn(rn @UserName varchar(200),rn @Password varchar(255)rn)rnASrnrnSELECTrn UserID rnrnFROMrn [User]rn rnWHERErn UserName = @UserName AND Password = @Passwordrnrnrnrn“/graduateproject”应用程序中的服务器错误。rn--------------------------------------------------------------------------------rnrn过程 'Pr_GetUserLogin' 需要参数 '@UserName',但未提供该参数。 rn说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 rnrn异常详细信息: System.Data.SqlClient.SqlException: 过程 'Pr_GetUserLogin' 需要参数 '@UserName',但未提供该参数。rnrn源错误: rnrnrn行 129: rn行 130: conn.Close();rn行 131: throw;rn行 132: rn行 133: finallyrn rnrn源文件: d:\graduateproject\App_Code\SqlHelper.cs 行: 131 rnrn堆栈跟踪: rnrnrn[SqlException (0x80131904): 过程 'Pr_GetUserLogin' 需要参数 '@UserName',但未提供该参数。]rn System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +95rn System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +82rn System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +346rn System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +3244rn System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +52rn System.Data.SqlClient.SqlDataReader.get_MetaData() +130rn System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +371rn System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +1121rn System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +334rn System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +45rn System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +162rn System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior) +87rn SqlHelper.ExecuteReader(String connectionString, CommandType cmdType, String cmdText, SqlParameter[] commandParameters) in d:\graduateproject\App_Code\SqlHelper.cs:131rn ResourceMananer.User.GetUserLogin(String sUserName, String sPassword) in d:\graduateproject\App_Code\User.cs:29rn _Default.logbt_Click(Object sender, EventArgs e) in d:\graduateproject\Default.aspx.cs:49rn System.Web.UI.WebControls.Button.OnClick(EventArgs e) +96rn System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +116rn System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31rn System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32rn System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +72rn System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3838rnrn 帮忙看看,谢谢啦!rn 论坛

需要参数 '@adminAccount',但未提供参数

05-08

“/”应用程序中的服务器错误。rn参数化查询 '(@adminAccount nvarchar(4000),@adminPwd nvarchar(4000),@adminRol' 需要参数 '@adminAccount',但未提供该参数。rn说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。rnrn异常详细信息: System.Data.SqlClient.SqlException: 参数化查询 '(@adminAccount nvarchar(4000),@adminPwd nvarchar(4000),@adminRol' 需要参数 '@adminAccount',但未提供该参数。rnrn源错误:rnrnrn行 110: SqlCommand cmd = new SqlCommand(sql, connection, transaction);rn行 111: cmd.Parameters.AddRange(values);rn行 112: int result = Convert.ToInt32(cmd.ExecuteScalar());rn行 113: return result;rn行 114: rnrnrn源文件: D:\我的文档\Desktop\DuoCai\DuoCaiDLL\DuoCaiDAL\DBHelper.cs 行: 112rnrn堆栈跟踪:rnrnrn[SqlException (0x80131904): 参数化查询 '(@adminAccount nvarchar(4000),@adminPwd nvarchar(4000),@adminRol' 需要参数 '@adminAccount',但未提供该参数。]rn System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +946986rn System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +821638rn System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +186rn System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1932rn System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +31rn System.Data.SqlClient.SqlDataReader.get_MetaData() +62rn System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297rn System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +1005rn System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132rn System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32rn System.Data.SqlClient.SqlCommand.ExecuteScalar() +137rn DuoCaiDLL.DuoCaiDAL.DBHelper.GetScalar(String sql, SqlParameter[] values) in D:\我的文档\Desktop\DuoCai\DuoCaiDLL\DuoCaiDAL\DBHelper.cs:112rn DuoCaiDLL.DuoCaiDAL.AdminInfoService.AdminAdd(AdminInfo admin) in D:\我的文档\Desktop\DuoCai\DuoCaiDLL\DuoCaiDAL\AdminInfoService.cs:35rn DuoCaiDLL.DuoCaiBLL.AdminInfoManager.AdminAdd(AdminInfo admin) in D:\我的文档\Desktop\DuoCai\DuoCaiDLL\DuoCaiBLL\AdminInfoManager.cs:33rn DuoCaiApple.DuoCaiBackManageSystem.WebBack.Admin_Add.btnAdd_Click(Object sender, EventArgs e) in D:\我的文档\Desktop\DuoCai\DuoCaiApple\DuoCaiBackManageSystem\WebBack\Admin_Add.aspx.cs:44rn System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105rn System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107rn System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7rn System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11rn System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33rn System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746rn 论坛

过程需要参数但未提供参数

04-07

做了个简单的三层,向数据库中添加东西,用得存储过程,因为不太熟悉,所以一直出现问题,但是我却不知道究竟什么地方出现了问题!请教大家!rnBLL层:rn public News SelectById(string id)rn rn return ndao.SelectById(id);rn rn public DataTable SelectByNewsId(string newsId)rn rn return cdao.SelectByNewsId(newsId);rn rnDAL层:rnpublic News SelectById(string id)rn rn //TODO:根据类别ID取出该条新闻主题内容rn News n = new News();rn DataTable dt = new DataTable();rn string cmdText = "news_selectById";//存储过程rn SqlParameter[] paras = new SqlParameter[] rn new SqlParameter("@id", id)rn ;rn dt = sqlhelper.ExecuteQuery(cmdText, paras, CommandType.StoredProcedure);rn n.Id = id;rn n.Title = dt.Rows[0]["title"].ToString();rn n.Content = dt.Rows[0]["content"].ToString();rn n.CreateTime = dt.Rows[0]["createTime"].ToString();rn n.CaId = dt.Rows[0]["caId"].ToString();rn return n;rn rnWEB层:rnprotected void Page_Load(object sender, EventArgs e)rn rn if (!Page.IsPostBack)rn rn string newsid =Request.QueryString["newsid"];rn NewsManager nm = new NewsManager();rn News news = nm.SelectById(newsid);rn //设置新闻主题rn lblTitle.Text = news.Title;rn lblContent.Text = news.Content;rn lblCreateTime.Text = news.CreateTime;rn //绑定新闻评论rn repComment.DataSource = new CommentManager().SelectByNewsId(newsid);rn repComment.DataBind();rn rn rn在运行过程中老提示说:过程 'news_selectById' 需要参数 '@id',但未提供该参数。 请大家帮忙给看看怎么回事。rn 论坛

参数化查询 '(@Name nvarchar(3)需要参数 '@TypeNum',但未提供参数

01-08

往sqlserver里面导入EXCEL数据rnrn[color=#FF0000]代码为:[/color]rnrn public partial class formCustMgs : Formrnrn rnrn public formCustMgs()rnrn rnrn InitializeComponent();rn rnrn private void btnImportFromExcel_Click(object sender, EventArgs e)rnrn rnrn using (FileStream stream = File.OpenRead(@"c:\khzl.xls"))rnrn rnrn HSSFWorkbook workbook = new HSSFWorkbook(stream);rnrn HSSFSheet sheet = workbook.GetSheetAt(0);rnrn for (int i = 1; i <= sheet.LastRowNum; i++)rnrn rnrn T_customers cust = new T_customers();rnrn HSSFRow row = sheet.GetRow(i);rnrn HSSFCell cellName = row.GetCell(0);rnrn cust.Name = cellName.StringCellValue;rnrn HSSFCell telPhone = row.GetCell(1);rnrn if (telPhone == null)rnrn rnrn cust.TelPhone = "";rnrn rnrn else if (telPhone.CellType == HSSFCell.CELL_TYPE_NUMERIC)rnrn rn cust.TelPhone = row.GetCell(1).NumericCellValue.ToString();rnrn rnrn elsernrn rnrn cust.TelPhone = row.GetCell(1).StringCellValue;rnrn rnrn HSSFCell mobilePhone = row.GetCell(2);rnrn if (mobilePhone == null)rnrn rnrn cust.MobilePhone = "";rnrn rnrn else if (mobilePhone.CellType == HSSFCell.CELL_TYPE_NUMERIC)rnrn rn cust.MobilePhone = row.GetCell(2).NumericCellValue.ToString();rnrn rnrn elsernrn rnrn cust.MobilePhone = row.GetCell(2).StringCellValue;rnrn rnrn HSSFCell postCode=row.GetCell(3);rnrn cust.PostCode = postCode.StringCellValue;rnrn cust.Address = "";rnrn cust.Email = "";rnrn cust.Address = "";rnrn HSSFCell dataTime = row.GetCell(6);rnrn cust.BuyDate = dataTime.DateCellValue;rnrn HSSFCell carNum=row.GetCell(7);rnrn cust.CarNum = carNum.StringCellValue;rnrn cust.BracktNum = row.GetCell(8).StringCellValue;rnrn cust.Brand = "";rnrn cust.Remarks = "";rnrn cust.Suggestion = "";rn new T_customersBLL().AddNew(cust);rnrn rnrn rnrn MessageBox.Show("录入成功");rnrnrn[color=#FF0000]BLL层为:[/color]rnrn partial class T_customersBLLrnrn rnrn public int AddNew(T_customers model)rnrn rnrn return new T_customersDAL().AddNew(model);rnrn rnrn public bool Delete(int id)rnrn rnrn return new T_customersDAL().Delete(id);rnrn rnrn public bool Update(T_customers model)rnrn rnrn return new T_customersDAL().Update(model);rnrn rnrn public T_customers Get(int id)rnrn rnrn return new T_customersDAL().Get(id);rnrn rnrn public IEnumerable ListAll()rnrn rnrn return new T_customersDAL().ListAll();rnrn rnrn rnrn[color=#FF0000]DAL层为:[/color]rnrnpublic int AddNew(T_customers model)rnrn rnrn string sql = "insert into T_customers (Name,TelPhone,MobilePhone,PostCode,Email,Address,BuyDate,CarNum,BracktNum,Brand,TypeNum,Suggestion,Remarks) output inserted.id values(@Name,@TelPhone,@MobilePhone,@PostCode,@Email,@Address,@BuyDate,@CarNum,@BracktNum,@Brand,@TypeNum,@Suggestion,@Remarks)";rnrn int id = (int)SqlHelper.ExecuteScalar(sql, new SqlParameter("Name", model.Name) , new SqlParameter("TelPhone", model.TelPhone)rnrn , new SqlParameter("MobilePhone", model.MobilePhone)rnrn , new SqlParameter("PostCode", model.PostCode)rnrn , new SqlParameter("Email", model.Email)rnrn , new SqlParameter("Address", model.Address)rnrn , new SqlParameter("BuyDate", model.BuyDate)rnrn , new SqlParameter("CarNum", model.CarNum)rnrn , new SqlParameter("BracktNum", model.BracktNum)rnrn , new SqlParameter("Brand", model.Brand)rnrn , new SqlParameter("TypeNum", model.TypeNum)rnrn , new SqlParameter("Suggestion", model.Suggestion)rnrn , new SqlParameter("Remarks", model.Remarks)rnrn );rnrn return id;rnrn rnrn[color=#FF0000]sqlHelper为:[/color]rnrn public static object ExecuteScalar(string cmdText,rnrn params SqlParameter[] parameters)rnrn rnrn using (SqlConnection conn = new SqlConnection(connstr))rnrn rnrn conn.Open();rnrn using (SqlCommand cmd = conn.CreateCommand())rnrn rnrn cmd.CommandText = cmdText;rnrn cmd.Parameters.AddRange(parameters);rnrn return cmd.ExecuteScalar();rnrn rnrn rnrn rnrn[color=#FF0000]问题:rnrn程序读到return cmd.ExecuteScalar();报错。[/color]rn报错代码:rnrn[color=#FF0000]参数化查询 '(@Name nvarchar(3),@TelPhone nvarchar(7),@MobilePhone nvarchar(4' 需要参数 '@TypeNum',但未提供该参数。[/color]rnrn各位高手求帮帮我,弄了一下午,没搞定,不知道哪里错了。MODEL取到值了,通过BLL可以传递过去。rn 论坛

参数化查询 '(@mbox varchar(150),@age int,@address varchar' 需要参数 '@mbox',但未提供参数

06-20

参数化查询 '(@mbox varchar(150),@age int,@phone varchar(50),@address varchar' 需要参数 '@mbox',但未提供该参数。rnpublic bool upinform()rn rn conn = new SqlConnection(connstr);rn string sql = "update admin set mailbox=@mbox,age=@age,phone=@phone,address=@address where username=@uname";rn tryrn rn conn.Open();rn SqlCommand comm = new SqlCommand(sql, conn);rn comm.Parameters.Add("@mbox", SqlDbType.VarChar, 150);rn comm.Parameters.Add("@age", SqlDbType.Int);rn comm.Parameters.Add("@phone",SqlDbType.VarChar,50);rn comm.Parameters.Add("@address",SqlDbType.VarChar,250);rn comm.Parameters.Add("@uname",SqlDbType.VarChar,16);rn comm.Parameters[0].Value = MailBox;rn comm.Parameters[1].Value = Age;rn comm.Parameters[2].Value = Phone;rn comm.Parameters[3].Value = Address;rn comm.Parameters[4].Value= UserName;rn int rows = Convert.ToInt16(comm.ExecuteScalar());rn if (rows > 0)rn rn return true;rn rn elsern rn return false;rn rn rn catch (System.Data.SqlClient.SqlException e)rn rn throw new Exception(e.Message);rn rn finallyrn rn conn.Close();rn rnrn rnrnpublic partial class hout : System.Web.UI.Pagernrn private string eid = "";rn protected void Page_Load(object sender, EventArgs e)rn rn if (!IsPostBack)rn rn if(Request.QueryString["username"]!=null)rn rn eid = Request.QueryString["username"].ToString();rn rn initu();rn rn rnrn private void initu()rn rn Admin ad = new Admin();rn ad.UserName = Session["username"].ToString();rn ad.upinform();rn rnrn protected void btup_Click(object sender, EventArgs e)rn rn Admin ad = new Admin();rn ad.UserName = Session["username"].ToString();rn ad.Age=int.Parse(upage.Text.Trim().Replace(" ",""));rn ad.MailBox = mailbox.Text.Trim().Replace(" ", "");rn ad.Phone = upphone.Text.Trim().Replace(" ", "");rn ad.Address = uptbaddress.Text.Trim().Replace(" ", "");rn if (!ad.upinform())rn rn Response.Write(" ");rn Response.Redirect("edituser.aspx");rn rn elsern rn Response.Write(" ");rn rnrn rn rnrnrn 论坛

参数化查询 '(@MNum varchar(50),@MName,'需要参数 '@MContent',但未提供参数

07-29

参数化查询 '(@MNum varchar(50),@MName varchar(50),@MSex int,@MBirthday datet' 需要参数 '@MContent',但未提供该参数。rnrnrn public int Member_Add(MyZoneOA.Model.OA.Member.Member model)rn rn StringBuilder strSql = new StringBuilder();rn strSql.Append("insert into Member(");rn strSql.Append("MNum,MName,MSex,MBirthday,MNumberID,DeptID,HAQTID,MBirthPlace,HRPTID,MTID,MWorkTime,MInTime,MHID,MModelWorker,MSSN,MResume,MContent,MState)");rn strSql.Append(" values (");rn strSql.Append("@MNum,@MName,@MSex,@MBirthday,@MNumberID,@DeptID,@HAQTID,@MBirthPlace,@HRPTID,@MTID,@MWorkTime,@MInTime,@MHID,@MModelWorker,@MSSN,@MResume,@MContent,@MState)");rn strSql.Append(";select @@IDENTITY");rn SqlParameter[] parameters = rn new SqlParameter("@MNum", SqlDbType.VarChar,50),rn new SqlParameter("@MName", SqlDbType.VarChar,50),rn new SqlParameter("@MSex", SqlDbType.Int,4),rn new SqlParameter("@MBirthday", SqlDbType.DateTime),rn new SqlParameter("@MNumberID", SqlDbType.VarChar,50),rn new SqlParameter("@DeptID", SqlDbType.Int,4),rn new SqlParameter("@HAQTID", SqlDbType.Int,4),rn new SqlParameter("@MBirthPlace", SqlDbType.VarChar,50),rn new SqlParameter("@HRPTID", SqlDbType.Int,4),rn new SqlParameter("@MTID", SqlDbType.Int,4),rn new SqlParameter("@MWorkTime", SqlDbType.DateTime),rn new SqlParameter("@MInTime", SqlDbType.DateTime),rn new SqlParameter("@MHID", SqlDbType.Int,4),rn new SqlParameter("@MModelWorker", SqlDbType.VarChar,50),rn new SqlParameter("@MSSN", SqlDbType.VarChar,50),rn new SqlParameter("@MResume", SqlDbType.VarChar,2000),rn new SqlParameter("@MContent", SqlDbType.VarChar,2000),rn new SqlParameter("@MState", SqlDbType.Int,4);rn parameters[0].Value = model.MNum;rn parameters[1].Value = model.MName;rn parameters[2].Value = model.MSex;rn parameters[3].Value = model.MBirthday;rn parameters[4].Value = model.MNumberID;rn parameters[5].Value = model.DeptID;rn parameters[6].Value = model.HAQTID;rn parameters[7].Value = model.MBirthPlace;rn parameters[8].Value = model.HRPTID;rn parameters[9].Value = model.MTID;rn parameters[10].Value = model.MWorkTime;rn parameters[11].Value = model.MInTime;rn parameters[12].Value = model.MHID;rn parameters[13].Value = model.MModelWorker;rn parameters[14].Value = model.MSSN;rn parameters[15].Value = model.MResume;rn parameters[15].Value = model.MContent;rn parameters[17].Value = model.MState;rnrn object obj = SqlHelper.GetSingle(strSql.ToString(), parameters);rn if (obj == null)rn rn return 0;rn rn elsern rn return Convert.ToInt32(obj);rn rn 论坛

没有更多推荐了,返回首页