我是 vb.net 的初学者,想知道如何在 Visual Studio 2005 中将窗口窗体连接到 SQL Server Express 数据库,以便我们以后可以对记录执行添加、搜索、更新和删除操作。
这是我的代码:
Dim mycommand As SqlCommand
Dim dr As SqlDataReader
Dim dr1 As SqlDataReader
Dim ra As Integer
Private Sub cmdsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsave.Click
Using myconnection As SqlConnection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\database\app.mdf;Integrated Security=True;User Instance=True")
myconnection.Open()
mycommand = New SqlCommand("insert into staff([FirstName],[LastName],[Address],[DOB], " & _
"[TelephoneNum], [DateJoinIn], [HighestQualifi], [AppointedAs], [Salary]) " & _
"VALUES (@first, @last, @address, @dob, @tel, @dateJ, @highQ, @appointed, @sal)", myconnection)
mycommand.Parameters.AddWithValue("@first", txtfname.Text)
mycommand.Parameters.AddWithValue("@last", txtlname.Text)
mycommand.Parameters.AddWithValue("@address", txtaddress.Text)
mycommand.Parameters.AddWithValue("@dob", txtdob.Text)
mycommand.Parameters.AddWithValue("@tel", txttelephone.Text)
mycommand.Parameters.AddWithValue("@dateJ", txtdjoinin.Text)
mycommand.Parameters.AddWithValue("@highQ", txthqualifi.Text)
mycommand.Parameters.AddWithValue("@appointed", txtappoint.text)
mycommand.Parameters.AddWithValue("@sal", txtsalary.Text)
mycommand.ExecuteNonQuery()
myconnection.Close()
End Using
End Sub
问题是它没有保存在我的数据库中??????请帮忙