Sub insertData()
Dim cmd As New SqlCommand
Dim da As New SqlDataAdapter
Dim dt As New DataTable
Dim ds As New DataSet
Dim strID As Integer
Dim strPartNo As String
Dim strFunc As String
Dim strHandle As String
Dim strMirror As String
Dim strUserDef1 As String
Dim strUserDef2 As String
Dim strUserDef3 As String
Dim strUserDef4 As String
Dim strUserDef5 As String
Try
' For i = tempMaxsrvArm To tempMaxsrvQgate
'i = i + 1
While (tempMaxsrvArm < tempMaxsrvQgate)
tempMaxsrvArm = tempMaxsrvArm + 1
With cmd
.Connection = mycon
.CommandType = CommandType.Text
.CommandText = "select * from Tape"
End With
da.SelectCommand = cmd
da.Fill(ds, "show") 'Keep data to Dataset
strID = ds.Tables("show").Rows.Add(tempMaxsrvArm)("ID").ToString
strPartNo = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("Partno").ToString
strFunc = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("Func").ToString
strHandle = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("Handle").ToString
strMirror = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("Mirror").ToString
strUserDef1 = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("UserDef1").ToString
strUserDef2 = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("UserDef2").ToString
strUserDef3 = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("UserDef3").ToString
strUserDef4 = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("UserDef4").ToString
strUserDef5 = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("UserDef5").ToString
With cmdCE
.Connection = conCE
.CommandType = CommandType.Text
.CommandText = "INSERT INTO [Tape] ([ID], [PartNo],Func,Handle,mirror,UserDef1,UserDef2,UserDef3,UserDef4,UserDef5) VALUES " & _
"('" & strID & "','" & strPartNo & "','" & strFunc & "','" & strHandle & "','" & strMirror & "','" & strUserDef1 & "','" & strUserDef2 & "','" & strUserDef3 & "','" & strUserDef4 & "','" & strUserDef5 & "')"
End With
cmdCE.ExecuteNonQuery()
' MessageBox.Show("Save Successfully")
ShowData()
' Next
End While
Catch exsql As SqlCeException
MsgBox(exsql.Message, MsgBoxStyle.Exclamation)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation)
End Try
End Sub
Sub updateData()
Dim cmd As New SqlCommand
Dim da As New SqlDataAdapter
Dim dt As New DataTable
Dim ds As New DataSet
Dim strID As Integer
Dim strPartNo As String
Dim strFunc As String
Dim strHandle As String
Dim strMirror As String
Dim strUserDef1 As String
Dim strUserDef2 As String
Dim strUserDef3 As String
Dim strUserDef4 As String
Dim strUserDef5 As String
Dim n As Integer
Dim MAX As Integer
Try
MAX = tempMaxsrvQgate + 1
For i = max To 0 Step -1
i = i - 1
' While (n < tempMaxsrvQgate)
'tempMaxsrvArm = tempMaxsrvArm + 1
With cmd
.Connection = mycon
.CommandType = CommandType.Text
.CommandText = "select * from Tape"
End With
da.SelectCommand = cmd
da.Fill(ds, "show") 'Keep data to Dataset
strID = ds.Tables("show").Rows.Add(i)("ID").ToString
strPartNo = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("Partno").ToString
strFunc = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("Func").ToString
strHandle = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("Handle").ToString
strMirror = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("Mirror").ToString
strUserDef1 = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("UserDef1").ToString
strUserDef2 = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("UserDef2").ToString
strUserDef3 = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("UserDef3").ToString
strUserDef4 = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("UserDef4").ToString
strUserDef5 = ds.Tables("show").Rows.Item(tempMaxsrvArm - 1)("UserDef5").ToString
With cmdCE
.Connection = conCE
.CommandType = CommandType.Text
' .CommandText = "UPDATE Tape SET Func = '" + strFunc + "' Where id = '" + strID + "',Partno = '" + strPartNo + "'"
.CommandText = "UPDATE Tape SET Func = '" + strFunc + "',Handle='" + strHandle + "',Mirror='" + strMirror + "',UserDef1='" + strUserDef1 + "',UserDef2='" + strUserDef2 + "',UserDef3='" + strUserDef3 + "',UserDef4='" + strUserDef4 + "',UserDef5='" + strUserDef5 + "' Where id = '" + strID + "',Partno = '" + strPartNo + "'"
End With
cmdCE.ExecuteNonQuery()
' MessageBox.Show("Save Successfully")
ShowData()
Next
' End While
Catch exsql As SqlCeException
MsgBox(exsql.Message, MsgBoxStyle.Exclamation)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation)
End Try
End Sub