Imports System.Data
Imports System.Data.SqlClient
Partial Class test
Inherits System.Web.UI.Page
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim txtName As String = TextName.Text
Dim txtcomment As String = TextComment.Text
Dim txtemail As String = TextEmail.Text
Dim con As SqlConnection
Dim cmd As SqlCommand
con.ConnectionString = "SqlData Source=(LocalDB)\v11.0;AttachDbFilename=App_Data\library.mdf; Integrated Security=True;Connect Timeout=30"
cmd.Connection = con
con.Open()
cmd.CommandText = "INSERT INTO table([Name], [Comment], [emailaddress]) VALUES([txtname], [txtcomment], [txtemail])"
cmd.ExecuteNonQuery()
con.Close()
End Sub
End Class
i am getting 'nullreferenceexecption was unhandled by user code' error in this code