本文介绍了将字符串拆分为12个字符的子字符串,然后插入数据库。请帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
私有 Sub SMSPort_DataReceived( ByVal 发件人作为 对象, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs)句柄 comPort.DataReceived
Dim str As String =
Dim temp 作为 字符串 =
objCon.GetConnectionString()
如果 e.EventType = SerialData .Chars 然后
短信Port.DtrEnable = True
System.Threading.Thread.Sleep( 100 )
tempp = SMSPort.ReadExisting()。替换( ?, )。修剪()
// ' 我想在这里添加split函数将12个以上的字符分成12个字符,然后输入数据库..
' for i As Integer = 1 to tempp.Length Step 12
' Debug.Write(Mid(tempp,i,12))
如果 tempp<> 然后
objCon .GetConnectionString()
objCon.GetConnection( 插入到tblAttended(Id,Status,Date,Time)值(' + tempp.ToString()+ ','in',' + System.DateTime.Today.ToShortDateString()+ ',' + DateTime.Now。 ToShortTimeString()+ '))
ListView1.Items.Add (tempp)
txtUniqueNumber.Text = tempp.Trim()
ListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent)
结束 如果
' 下一个我
Control.CheckForIllegalCrossThreadCalls = 错误
结束 Sub
解决方案
Private Sub SMSPort_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles comPort.DataReceived Dim str As String = "" Dim temp As String = "" objCon.GetConnectionString() If e.EventType = SerialData.Chars Then SMSPort.DtrEnable = True System.Threading.Thread.Sleep(100) tempp = SMSPort.ReadExisting().Replace("", "").Trim() //' iwant to add here split function to split more than 12 charcters into only 12 character then give entry into database.. 'For i As Integer = 1 To tempp.Length Step 12 ' Debug.Write(Mid(tempp, i, 12)) If tempp <> "" Then objCon.GetConnectionString() objCon.GetConnection("Insert into tblAttended(Id,Status,Date,Time)values('" + tempp.ToString() + "','In','" + System.DateTime.Today.ToShortDateString() + "','" + DateTime.Now.ToShortTimeString() + "')") ListView1.Items.Add(tempp) txtUniqueNumber.Text = tempp.Trim() ListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent) End If 'Next i Control.CheckForIllegalCrossThreadCalls = False End Sub
解决方案
这篇关于将字符串拆分为12个字符的子字符串,然后插入数据库。请帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!