使用TimeStamp将COM端口数据保存到SQL Server [英] Save COM Port data to a SQL Server with TimeStamp

查看:78
本文介绍了使用TimeStamp将COM端口数据保存到SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是在COM端口显示的数据。我将传入的数据保存到String,然后显示该字符串中的子字符串。



我需要将带有TimeStamp的子串保存到SQL Server数据库。我需要做些什么呢?







I am display data which is coming at COM Port. I am saving that incoming data to a String and then displaying sub string from that string.

I need to save substrings with TimeStamp to a SQL Server Database. What i need to do for it ?



private void DisplayData(MessageType type, string msg)
        {
           richTextBox1.Invoke(new EventHandler(delegate
            {

                string substring = string.Empty;
              if (msg.Length > 54)
                    substring = msg.Substring(54, 3);
                 richTextBox1.AppendText(substring) ;

            }));
        }
        #endregion

推荐答案

您需要检查的是将长度检查从54更改为54 + 3 57,这确保您有总共57个字符串并且只有当54 + 3个字符在msg字符串中时它才会执行解析。



/编辑

是这样的吗?

All you need to check is change the length checking from 54 to 54+3 57 which make sure''s that you have total 57 strings and it executes the parse only when 54 +3 char''s are in msg string.

/Edit
was it like this?
if (msg.Length > 57)
           substring = msg.Substring(54, 3); 

肯定会有工作


这篇关于使用TimeStamp将COM端口数据保存到SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆