C#中操作Oracle时的SQL语句参数的用法

None.gif OracleTransaction myTrans ;
None.gif            conn.Open();
None.gif            myTrans 
= conn.BeginTransaction(IsolationLevel.ReadCommitted);
None.gif            comm.Transaction 
= myTrans;
None.gif            comm.CommandText
= " insert into TagInfo(TagID,AutoSubSysID,TagCode,TagName,TagType,TagValueType,TagMaxValue,TagMinValue,TagAlartMax " ;
None.gif            comm.CommandText
+= "                    ,TagAlartMin,TagSaveInterval,TagSaveIgBand,ValidTerm,TimeStampMode,TagAlartPos " ;
None.gif            comm.CommandText
+= "                      ,TagAlartPosDes,Description)  " ;
None.gif            comm.CommandText
+= "              values(trim(to_char(SeqTagID.Nextval ,'0000000000')),'0000000100',:TagCode,:TagName,:TagType,:TagValueType,:TagMaxValue,:TagMinValue,:TagAlartMax " ;
None.gif            comm.CommandText
+= "                      ,:TagAlartMin,:TagSaveInterval,:TagSaveIgBand,:ValidTerm,:TimeStampMode,:TagAlartPos " ;
None.gif            comm.CommandText
+= "                      ,:TagAlartPosDes,:Description) " ;
None.gif
ExpandedBlockStart.gifContractedBlock.gif            OracleParameter [] parameterValue 
=   dot.gif {
InBlock.gif                                                    
new OracleParameter("TagCode",OracleType.VarChar,20)//0
InBlock.gif
                                                    ,new OracleParameter("TagName",OracleType.VarChar,40)
InBlock.gif                                                    ,
new OracleParameter("TagType",OracleType.Char,1)
InBlock.gif                                                    ,
new OracleParameter("TagValueType",OracleType.Char,1)
InBlock.gif                                                    ,
new OracleParameter("TagMaxValue",OracleType.Double)
InBlock.gif                                                    ,
new OracleParameter("TagMinValue",OracleType.Double)
InBlock.gif                                                    ,
new OracleParameter("TagAlartMax",OracleType.Double)
InBlock.gif                                                    ,
new OracleParameter("TagAlartMin",OracleType.Double)
InBlock.gif                                                    ,
new OracleParameter("TagSaveInterval",OracleType.Int32)
InBlock.gif                                                    ,
new OracleParameter("TagSaveIgBand",OracleType.Double)
InBlock.gif                                                    ,
new OracleParameter("ValidTerm",OracleType.Int32)
InBlock.gif                                                    ,
new OracleParameter("TimeStampMode",OracleType.Char,1)
InBlock.gif                                                    ,
new OracleParameter("TagAlartPos",OracleType.Int32)
InBlock.gif                                                    ,
new OracleParameter("TagAlartPosDes",OracleType.VarChar,40)
InBlock.gif                                                    ,
new OracleParameter("Description",OracleType.VarChar,80)
ExpandedBlockEnd.gif                                                }
;
None.gif            
foreach (OracleParameter parameter  in  parameterValue) comm.Parameters.Add(parameter);
None.gif
None.gif            
int  m,n;
None.gif
None.gif            
try
ExpandedBlockStart.gifContractedBlock.gif            
dot.gif {                
InBlock.gif                        
InBlock.gif                
for(int j=3;j<=30;j++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    m
=j;
InBlock.gif                    
for(int i=1;i<12;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        n
=i;
InBlock.gif                        
string TagID="";
InBlock.gif                        
string TagCode ="00100100010100";
InBlock.gif                        
string TagName ="RLS";
InBlock.gif
InBlock.gif                        
//TagCode
InBlock.gif
                        TagCode +=(j<10)?"0"+j.ToString():j.ToString();
InBlock.gif                        TagCode 
+=(i<10)?"000"+i.ToString():"00"+i.ToString();                    
InBlock.gif                        parameterValue[
0].Value = TagCode;
InBlock.gif
InBlock.gif                        
//TagName
InBlock.gif
                        TagName +=(j<10)?"000"+j.ToString():"00"+j.ToString();
InBlock.gif                        TagName 
+=(i<10)?"000"+i.ToString():"00"+i.ToString();
InBlock.gif                        parameterValue[
1].Value = TagName;
InBlock.gif
InBlock.gif                        
//TagType
InBlock.gif
                        parameterValue[2].Value =(i<5)? '0':'2';
InBlock.gif
InBlock.gif                        
//TagValueType
InBlock.gif
                        parameterValue[3].Value=(i==1 || i>=6)?'0':'1';
InBlock.gif                                                        
InBlock.gif                        
//TagMaxValue
InBlock.gif
                        if(i==1 ||i==9)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            parameterValue[
4].Value=10000;
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        
else if(i>=2 && i<6)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            parameterValue[
4].Value=1;
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        
else if(i==6)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            parameterValue[
4].Value=3600;
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        
else if(i==7)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            parameterValue[
4].Value=300;
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        
else if(i==8)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            parameterValue[
4].Value=10;
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        
else if(i==10)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            parameterValue[
4].Value=DBNull.Value;
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        
else if(i==11)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            parameterValue[
4].Value=600;
ExpandedSubBlockEnd.gif                        }

InBlock.gif
InBlock.gif                        
//TagMinValue
InBlock.gif
                        if((i>=1 && i<6)||(i>=9 &&i<11))
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            parameterValue[
5].Value=0;
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        
else if(i==6)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            parameterValue[
5].Value=10;
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        
else if(i==7 ||i==11)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            parameterValue[
5].Value=5;
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        
else if(i==8)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            parameterValue[
5].Value=2;
ExpandedSubBlockEnd.gif                        }

InBlock.gif                            
InBlock.gif                        
//TagAlartMax
InBlock.gif
                        parameterValue[6].IsNullable=true;
InBlock.gif                        
if((i==1))    parameterValue[6].Value=10000;
InBlock.gif                        
else parameterValue[6].Value=DBNull.Value;
InBlock.gif                            
InBlock.gif                        
//TabAlartMin
InBlock.gif
                        parameterValue[7].Value =(i==1)?1:0;
InBlock.gif
InBlock.gif                        
//TagSaveInterval
InBlock.gif
                        if(i==1)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            parameterValue[
8].Value=10000;
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        
else if(i>=2 && i<=5)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            parameterValue[
8].Value=20000;
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        
else if(i>5)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            parameterValue[
8].Value=60000;
ExpandedSubBlockEnd.gif                        }

InBlock.gif
InBlock.gif                        
//TagSaveIgBand
InBlock.gif
                        if((i==1))    parameterValue[9].Value=2;
InBlock.gif                        
else parameterValue[9].Value=1;
InBlock.gif                            
InBlock.gif                        
//ValidTerm
InBlock.gif
                        parameterValue[10].Value =(i==1)?60000:300000;
InBlock.gif
InBlock.gif                        
//TimeStampMode
InBlock.gif
                        parameterValue[11].Value="0";
InBlock.gif
InBlock.gif                        
//TagAlartPos
InBlock.gif
                        parameterValue[12].IsNullable=true;
InBlock.gif                        
if((i>=1&& (i<=4)) parameterValue[12].Value =0;
InBlock.gif                        
else parameterValue[12].Value =DBNull.Value;
InBlock.gif                        
//TagAlartPosDes
InBlock.gif
                        parameterValue[13].Value =(i>=2 && i<=4)?"异常":"";
InBlock.gif
InBlock.gif                        
//Description
InBlock.gif
                        parameterValue[14].Value ="";
InBlock.gif
InBlock.gif                        comm.ExecuteNonQuery();
posted on 2006-05-26 23:41  偷回忆的人 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/liuwenjun830/archive/2006/05/26/410414.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值