一区二区三区日韩精品-日韩经典一区二区三区-五月激情综合丁香婷婷-欧美精品中文字幕专区

分享

C# oracle 參數(shù)傳遞的多種方式 留著復(fù)習(xí)

 _明心見性_ 2017-11-13

下邊的代碼就會(huì)造成  ORA-01036 非法的變量名/編號(hào)




C#代碼  



  1. cmd.CommandText = "SELECT * FROM kk.kkyh WHERE id = @comboBox1 and password = @textBox1 ";  

  2.   

  3. cmd.Parameters.Add("@comboBox1", OracleType.VarChar).Value = comboBox1.Text;  

  4. cmd.Parameters.Add("@textBox1", OracleType.VarChar).Value = textBox1.Text;  


 


把SQL中的@改成:,把.Add中的@去掉,就正常了


 




C#代碼  



  1. cmd.CommandText = "SELECT * FROM kk.kkyh WHERE id = :comboBox1 and password = :textBox1 ";  

  2.   

  3. cmd.Parameters.Add("comboBox1", OracleType.VarChar).Value = comboBox1.Text;  

  4. 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è)問題了


==============================================================

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多

    激情国产白嫩美女在线观看| 国产亚洲午夜高清国产拍精品| 国产精品不卡一区二区三区四区| 内用黄老外示儒术出处| 特黄大片性高水多欧美一级| 丰满人妻熟妇乱又乱精品古代| 日韩中文字幕欧美亚洲| 97人妻精品一区二区三区免| 九九热这里只有精品哦| 69精品一区二区蜜桃视频| 美女黄色三级深夜福利| 成人亚洲国产精品一区不卡| 婷婷色网视频在线播放| 亚洲最新的黄色录像在线| 午夜福利精品视频视频| 亚洲国产精品久久琪琪| 日韩午夜老司机免费视频| 国产又黄又爽又粗视频在线| 亚洲一区二区三区四区性色av| 色婷婷国产精品视频一区二区保健 | 国产日产欧美精品视频| 老富婆找帅哥按摩抠逼视频| 婷婷开心五月亚洲综合| 国产韩国日本精品视频| 国产一区欧美一区二区| 草草夜色精品国产噜噜竹菊| 国产精品午夜视频免费观看| 黄色国产一区二区三区| 日韩精品免费一区三区| 熟妇人妻av中文字幕老熟妇| 老司机精品福利视频在线播放| 亚洲乱妇熟女爽的高潮片| 高中女厕偷拍一区二区三区| 日本av一区二区不卡| 国产永久免费高清在线精品| 亚洲国产精品久久精品成人| 嫩呦国产一区二区三区av| 日韩精品视频免费观看| 亚洲丁香婷婷久久一区| 国产精品伦一区二区三区四季| 欧美一级片日韩一级片 |