这是我在数据表中插入数据的代码。当Execute
我收到消息“成功”时。但是数据表中不存在数据。
Imports System.Data
Imports System.Data.SqlClient
Partial Public Class _Default
Inherits System.Web.UI.Page
Dim s As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=G:\ANDY\Dot Net.Practical\SQL DATA BASE\inserting4\inserting4\App_Data\location.mdf;Integrated Security=True;User Instance=True"
Dim sql As String
Dim con As New SqlConnection
Dim cmd As SqlCommand
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
con = New SqlConnection(s)
con.Open()
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
sql = "insert into location(name,street,city)values(@name,@street,@city)"
cmd = New SqlCommand(sql, con)
cmd.Parameters.Add("@name", SqlDbType.NVarChar).Value = TextBox1.Text
cmd.Parameters.Add("@street", SqlDbType.NVarChar).Value = TextBox2.Text
cmd.Parameters.Add("@city", SqlDbType.NVarChar).Value = TextBox3.Text
cmd.ExecuteNonQuery()
MsgBox("SUCCESS")
End Sub
End Class