Protected Sub Insert(ByVal sender As Object, ByVal e As EventArgs) Dim name As String = txtName.Text Dim country As String = txtCountry.Text Dim query As String = "INSERT INTO Customers VALUES(@Name, @Country)" Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString txtName.Text = "" txtCountry.Text = "" Using con As SqlConnection = New SqlConnection(constr) Using cmd As SqlCommand = New SqlCommand(query) cmd.Parameters.AddWithValue("@Name", name) cmd.Parameters.AddWithValue("@Country", country) cmd.Connection = con con.Open() cmd.ExecuteNonQuery() con.Close() End Using End Using
Me.BindGrid() End Sub