於.NET輸入資料後, 將其存至SQL Server中
Dim SQLConnect = New SqlConnection
Dim SQLCommand = New SqlCommand
Dim xlIFMUploadDate As String
Dim xlIFMUploadName As String
Dim xlIFMUploadValue As String
Dim i As Integer
Try
'建立與SQL連線語法
SQLConnect.ConnectionString = "Data Source=C4C017840;Initial Catalog=FAC4DB;Persist Security Info=True;User ID=sa;Password=sa;Connect Timeout=30"
'開啟連線
SQLConnect.Open()
'設定SQL指令_Insert Data
SQLCommand.Connection = SQLConnect
xlIFMUploadDate = Now()
For i = 0 To 11
xlIFMUploadName = arrxlIFMNameTACTOCThirdName(i)
xlIFMUploadValue = LSet(arrxlIFMNameTACTOCThirdValue(i), 10)
SQLCommand.CommandText = "Insert into [dbo].[Transfer_Table] ([TF_Data_Source], [TF_Data_Gen_Time], [TF_Tagname], [TF_Value], [TF_Ack_Flag], [TF_SN]) Values ('Real_Time_Data', '" + xlIFMUploadDate + "', '" + xlIFMUploadName + "', '" + xlIFMUploadValue + "', '', '')"
'執行SQL指令
SQLCommand.ExecuteNonQuery()
Next
For i = 0 To 104
xlIFMUploadName = arrxlIFMNameTACTOCFourthName(i)
xlIFMUploadValue = LSet(arrxlIFMNameTACTOCFourthValue(i), 10)
SQLCommand.CommandText = "Insert into [dbo].[Transfer_Table] ([TF_Data_Source], [TF_Data_Gen_Time], [TF_Tagname], [TF_Value], [TF_Ack_Flag], [TF_SN]) Values ('Real_Time_Data', '" + xlIFMUploadDate + "', '" + xlIFMUploadName + "', '" + xlIFMUploadValue + "', '', '')"
'執行SQL指令
SQLCommand.ExecuteNonQuery()
Next
Catch ex As Exception
MessageBox.Show("Insert Transfer table Error: " & ex.Message)
Finally
'關閉連線
SQLConnect.Close()
End Try
留言列表