1 string sql = "insert into personinfo " + 2 "(id,employeename,employeecode, " + 3 "values(:id,:employeename,:employeecode, " )"; 4 OracleParameter[] pars = { new OracleParameter("id",t.Id), 5 new OracleParameter(":employeename",t.EmployeeName), 6 new OracleParameter(":employeecode",t.EmployeeCode) 7 }; 8 return OracleDBHelper.ExecuteSql(sql, CommandType.Text, pars);
1 StringBuilder strSql=new StringBuilder(); 2 strSql.Append("insert into Books("); 3 strSql.Append("Title,Author,PublisherId)"); 4 strSql.Append(" values ("); 5 strSql.Append("@Title,@Author,@PublisherId)"); 6 strSql.Append(";select @@IDENTITY"); 7 SqlParameter[] parameters = { 8 new SqlParameter("@Title", SqlDbType.NVarChar,200), 9 new SqlParameter("@Author", SqlDbType.NVarChar,200), 10 new SqlParameter("@PublisherId", SqlDbType.Int,4)}; 11 parameters[0].Value = model.Title; 12 parameters[1].Value = model.Author; 13 parameters[2].Value = model.Publisher.Id ; 14 15 object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters); 16 if (obj == null) 17 { 18 return 1; 19 } 20 else 21 { 22 return Convert.ToInt32(obj); 23 }
在Oracle数据库中,参数替换不能使用"@",要使用":"
时间: 2024-10-05 22:59:08