phy小雨
2023-01-12 23:44
VM算法平台

在流程中写脚本,将识别出来的字符update到SQLsever里面,帮忙看看是哪里写的不对!

把in0的结果写入数据库CHENGZHONG的NOW表里面;

编译没有报错,但是数据库里面的值也写不进去。求助!




using System;
using System.Text;
using System.Windows.Forms;
using Script.Methods;
using Microsoft.VisualBasic;
using Microsoft.CSharp;
using System.Runtime;
using System.Data.SqlClient;
using System.Data.Entity;
using System.Data;

public partial class UserScript:ScriptMethods,IProcessMethods
{
    //the count of process
    //执行次数计数
    int processCount ;  
    string in1;
    string in2;
    int i;
    string aa;
    int len1;
    int bijiao;
    int bijiao1;
    int bijiao2;
   
    /// <summary>
    /// Initialize the field's value when compiling
    /// 预编译时变量初始化
    /// </summary>
    public void Init()
    {
        //You can add other global fields here
        //变量初始化,其余变量可在该函数中添加
        processCount = 0;
        in1 = "?";
       
    }

    /// <summary>
    /// Enter the process function when running code once
    /// 流程执行一次进入Process函数
    /// </summary>
    /// <returns></returns>
    public bool Process()
    {
     // MyConn = "Provider=SQLOLEDB.1; Integrated Security=SSPI; Persist Security Info=False; Initial Catalog=CHENGZHONG;Data Source=DESKTOP-PM6NF1O\\WINCC";
       // MyConn="DataSource=DESKTOP-PM6NF1O\WINCC;Initial Catalog=CHENGZHONG;Persist Security Info=True;User ID=sa;Password=12345678";
      // MyConn=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
       //MyConn="Provider=SQLOLEDB.1; Integrated Security=SSPI; Persist Security Info=False; Initial Catalog=CHENGZHONG;Data Source=DESKTOP-PM6NF1O\WINCC";      
      // string MyConn="server=127.0.0.1;uid=user;pwd=123456;database=Northwind;Trusted_Connection=no";
        //SqlConnection MyConnection=new SqlConnection(MyConn);
       //SqlConnection MyConnection=new SqlConnection(MyConn);
       //MyConnection.Open();
       //out0 = string.Compare(in0,in1);  //字符比较
        //out2 = in2.Substring(0,1); //截取字符
        


        len1 = System.Text.Encoding.Default.GetByteCount(in0);//获取字符串的长度
        len = len1;   //实体化 
        bijiao = 1;  
        in2 = in0;
        //写入数据库
        
        
        
         //string MyConn = "Provider=SQLOLEDB.1; Integrated Security=SSPI; Persist Security Info=False; Initial Catalog=CHENGZHONG;Data Source=DESKTOP-PM6NF1O\\WINCC";
         string MyConn="Data Source=192.168.1.8,1433;Ne**ork Library=DBMSSOCN;Initial Catalog=CHENGZHONG;uid=sa;Password=12345678 " ;//定义数据库连接参数 
         SqlConnection MyConnection=new SqlConnection(MyConn);
         string MyUpdate = "UPDATE NOW set outstring = 'in0' WHERE name = '1'";        //写入数据库的位置
         SqlCommand MyCommand=new SqlCommand(MyUpdate,MyConnection);
         MyConnection.Open();                                                                                //打开数据库
         MyCommand.ExecuteNonQuery();  
         MyConnection.Close();                                                                                  //关闭数据库
 
    

          for(i=0;i<len1;i++)     //循环字符的长度
        {
               aa = in2.Substring(i,1); //循环右移取字符
               bijiao1 = string.Compare(aa,in1);  //in1 = "?";循环自增比较,有"?"的时候bijiao1=0
               if(bijiao1==0)
                {
                   bijiao = bijiao&0;
               }
              
             
          }
        out1 = i;
        out0 = bijiao;
        out2 = in1;
        out3 = bijiao1;
        out4 = aa;
        //判断bijiao =1 时
        if (bijiao==0)
        {
        NG = "NG";
        jieguo = 0;
        }    
        else
        {
        NG = "";
        jieguo = 1;
        }
         if (zifu==0)
        {
        NG = "NG";
        jieguo = 0;
        }    
        else
        {
        NG = "";
        jieguo = 1;
        }
        
        //You can add your codes here, for realizing your desired function
        //每次执行将进入该函数,此处添加所需的逻辑流程处理
      return true;   
       
    }

}
                             [图片][图片]

[图片]

  • 68
  • 2
  • 分享

全部回答1

您好,编译通过并不能确保代码能够正常运行,编译只是检查明显的语法错误。你可以看下运行的时候模块状态是1还是0.如果是0则表明脚本里面有代码执行异常了。可以通过try()catch()的方式,判断具体的**是否执行成功。

2023-01-18 16:26
    |
  • 评论
  • |

请升级浏览器版本

您正在使用的浏览器版本过低,请升级最新版本以获得更好的体验。

推荐使用以下浏览器