下邊的代碼就會(huì)造成 ORA-01036 非法的變量名/編號(hào)
- cmd.CommandText = "SELECT * FROM kk.kkyh WHERE id = @comboBox1 and password = @textBox1 ";
-
- cmd.Parameters.Add("@comboBox1", OracleType.VarChar).Value = comboBox1.Text;
- cmd.Parameters.Add("@textBox1", OracleType.VarChar).Value = textBox1.Text;
把SQL中的@改成:,把.Add中的@去掉,就正常了
- cmd.CommandText = "SELECT * FROM kk.kkyh WHERE id = :comboBox1 and password = :textBox1 ";
-
- cmd.Parameters.Add("comboBox1", OracleType.VarChar).Value = comboBox1.Text;
- cmd.Parameters.Add("textBox1", OracleType.VarChar).Value = textBox1.Text;
黑色頭發(fā) http://heisetoufa.
===============================================================
最近寫程序,用EnterpriseLibrary往Oracle中插入數(shù)據(jù),出現(xiàn)錯(cuò)誤ORA-01036:非法的變量名/編號(hào),代碼如下: DbConnection m_con = g_db.CreateConnection(); m_con.Open(); DbCommand m_com = g_db.GetSqlStringCommand("insert into USER_DEPARTMENT(DEPARTNAME,PARENTDEPID) values(@departname,@parentdepid)"); g_db.AddInParameter(m_com, "@departname", DbType.String, this.TextBox1.Text); g_db.AddInParameter(m_com, "@parentdepid", DbType.String, this.TreeView1.SelectedNode.Value); g_db.ExecuteNonQuery(m_com); m_con.Close(); 若換成 DbCommand m_com = g_db.GetSqlStringCommand("insert into USER_DEPARTMENT(DEPARTNAME,PARENTDEPID) values('" + this.TextBox1.Text + "','" + this.TreeView1.SelectedNode.Value + "')"); 則沒有問題,上網(wǎng)查也沒找到解決辦法,經(jīng)過一番探索,終于找到原因了,Oracle中好象不支持@,把@換成:就可以了,代碼如下: DbConnection m_con = g_db.CreateConnection(); m_con.Open(); DbCommand m_com = g_db.GetSqlStringCommand("insert into USER_DEPARTMENT(DEPARTNAME,PARENTDEPID) values(:departname,:parentdepid)"); g_db.AddInParameter(m_com, ":departname", DbType.String, this.TextBox1.Text); g_db.AddInParameter(m_com, ":parentdepid", DbType.String, this.TreeView1.SelectedNode.Value); g_db.ExecuteNonQuery(m_com); m_con.Close();
另外,Oracle中如果不用begin...end,SQL語(yǔ)句中不要有分號(hào)(;)。
========================================================
publicbool ModifyDrawBill(MDrawBill mBill) { StringBuilder strSQLText =new StringBuilder(); strSQLText.Append("update DrawBill set "); OracleParameter[] param = { new OracleParameter("PKID", OracleType.Int32), new OracleParameter("StationId", OracleType.VarChar), new OracleParameter("BillBegin", OracleType.VarChar), new OracleParameter("BillEnd", OracleType.VarChar), new OracleParameter("SumCount", OracleType.Int32), new OracleParameter("DrawDate", OracleType.DateTime), new OracleParameter("IsConfirm", OracleType.Int32), new OracleParameter("AppUser", OracleType.NVarChar), new OracleParameter("CheckUser", OracleType.NVarChar), new OracleParameter("Memo", OracleType.NVarChar) }; //@@lwd 20110803 param[0].Value = mBill.PKID; if (mBill.StationId !=null) { strSQLText.Append("StationId=:StationId,"); param[1].Value = mBill.StationId; } if (mBill.BillBegin !=null) { strSQLText.Append("BillBegin=:BillBegin,"); param[2].Value = mBill.BillBegin; } if (mBill.BillEnd !=null) { strSQLText.Append("BillEnd=:BillEnd,"); param[3].Value = mBill.BillEnd; } if (mBill.SumCount !=null) { strSQLText.Append("SumCount=:SumCount,"); param[4].Value = mBill.SumCount; } if (mBill.DrawDate !=null) { strSQLText.Append("DrawDate=:DrawDate,"); param[5].Value = mBill.DrawDate; } if (mBill.IsConfirm !=null) { strSQLText.Append("IsConfirm=:IsConfirm,"); param[6].Value = mBill.IsConfirm; } if (mBill.AppUser !=null) { strSQLText.Append("AppUser=:AppUser,"); param[7].Value = mBill.AppUser; } if (mBill.CheckUser !=null) { strSQLText.Append("CheckUser=:CheckUser,"); param[8].Value = mBill.CheckUser; } if (mBill.Memo !=null) { strSQLText.Append("Memo=:Memo,"); param[9].Value = mBill.Memo; } if (strSQLText.ToString().EndsWith(",")) { strSQLText = strSQLText.Remove(strSQLText.ToString().Length -1, 1);
} strSQLText.Append(" where PKID=:PKID "); return OracleHelper.ExecuteNonQuery(OracleHelper.Connection_String, CommandType.Text, strSQLText.ToString(), param) >0;//提示“RA-01036: 非法的變量名/編號(hào)” }
==================================================
string sql = " select rownum as logrow,Id,UserId,UserLogCategoryId,SystemLogCategoryId,Time,ReadT,Title,Content,Permission from LogT where UserId=:UserId and Title like :Title "; if (Title == null) Title = ""; Title = "%" + Title + "%"; OracleParameter[] paras = new OracleParameter[] { new OracleParameter(":UserId", UserId) , new OracleParameter(":Title", Title)};
======================================================================================================
oracle中錯(cuò)誤ORA-01036: 非法的變量名/編號(hào)
C# public Result AddUser(UserEntity user) { Result result = new Result(true); DbCommand dbCmd = db.GetSqlStringCommand("PK_TY_USER.INS_USER"); db.AddInParameter(dbCmd, "id", DbType.Int32, user.Id); db.AddInParameter(dbCmd, "names", DbType.String, user.Name); db.AddInParameter(dbCmd, "sex", DbType.String, user.Sex); db.AddInParameter(dbCmd, "nav", DbType.String, user.Native_Place); db.AddInParameter(dbCmd, "birday", DbType.DateTime, user.Birthday); db.AddInParameter(dbCmd, "age", DbType.Int32, user.Age); try { db.ExecuteNonQuery(dbCmd); } catch (Exception ex) { result.Success = false; result.Error = ex; throw ex; } return result; } oracle procedure INS_USER(id in integer,names in varchar2,sex in varchar2,nav in varchar2,birday in date,age in integer) is begin insert into ty_user values(id,names,sex,nav,birday,age); end; oracle中測(cè)試能過
==========================================================================
最近寫程序時(shí),往Oracle中插入數(shù)據(jù),出現(xiàn)錯(cuò)誤ORA-01036:非法的變量名/編號(hào),代碼如下: DbConnection conn = GetCon(); conn.Open(); DbCommand cmd = conn.CreateCommand(); string sqlrt= "insert into T_User(Id,Name,Password,E_Mail) VALUES(@id,@name,@password,@email)"; cmd.CommandText = sqlrt; cmd.Parameters.Add(new SqlParameter("@id", Convert.ToInt32(txtId.Text))); cmd.Parameters.Add(new SqlParameter("@name", txtName.Text)); cmd.Parameters.Add(new SqlParameter("@password", txtPassword.Text)); cmd.Parameters.Add(new SqlParameter("@email", txtEmail.Text)); int num = cmd.ExecuteNonQuery(); if (num > 0) { Response.Write("插入成功"); DataLoad(); } 解決方案是: DbConnection conn = GetCon(); conn.Open(); DbCommand cmd = conn.CreateCommand(); string sqlrt= "insert into T_User(Id,Name,Password,E_Mail) VALUES(:id,:name,:password,:email)"; cmd.Parameters.Add(new OracleParameter(":id", Convert.ToInt32(txtId.Text))); cmd.Parameters.Add(new OracleParameter(":name", txtName.Text)); cmd.Parameters.Add(new OracleParameter(":password", txtPassword.Text)); cmd.Parameters.Add(new OracleParameter(":email", txtEmail.Text)); 在Oracle數(shù)據(jù)庫(kù)中,參數(shù)替換不能使用"@",要使用":",將程序中的@替換成就可以解決這個(gè)問題了
==============================================================
|