
February 28th, 2007, 11:45 AM
|
|
Registered User
|
|
Join Date: Oct 2006
Posts: 6
Time spent in forums: 2 h 18 m 35 sec
Reputation Power: 0
|
|
|
[Help] Cannot insert record
Hi, I'm a VB newbie and I want to write a simple program that insert a record to a .mdf file after pressing a button.
I've write the following code but the code doesn't work.
The program doesn't do anything after I press the button.
Is the code has something wrong?
Please help
Code:
Private Sub btn100_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn100.Click
Dim conn As New SqlConnection
conn.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector y|\db.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
conn.Open()
Dim sql As String = "INSERT INTO Point(Point, IsUsed) VALUES (100, 0)"
Dim cmd As New SqlCommand(sql, conn)
Try
cmd.ExecuteNonQuery()
Catch x As SqlException
Label3.Text = x.Message
End Try
cmd.Connection.Close()
dgPoint.Refresh()
End Sub
|