我做了一个小应用程序,将插入数据保存到表中......
应用程序关闭后应用程序不保存数据..
谁能告诉我代码中有什么问题。
Imports System.Data
Imports System.Data.SqlServerCe
Public Class Form1
Public connstring As New String("Data Source=|DataDirectory|\test_db.sdf")
Public sqlconn As New SqlCeConnection(connstring)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim name As New String("jaifar")
Dim myCommand As New SqlCeCommand("Insert Into table1 (id) Values('" + name + "')", sqlconn)
If sqlconn.State = Data.ConnectionState.Closed Then sqlconn.Open()
myCommand.ExecuteNonQuery()
Me.Table1TableAdapter.Fill(Me.Test_dbDataSet1.table1)
End Sub
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
sqlconn.Close()
sqlconn = Nothing
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Test_dbDataSet1.table1' table. You can move, or remove it, as needed.
Me.Table1TableAdapter.Fill(Me.Test_dbDataSet1.table1)
End Sub
End Class