VB.Net
Imports System.Data.SqlClient
Imports System.Configuration
Public Class Form1
Private Sub btnInsert_Click(sender As Object, e As EventArgs) Handles btnInsert.Click
Dim connectionString As String = ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString
Dim name As String = txtName.Text ' Assuming you have a TextBox named txtName for the name input
Dim email As String = txtEmail.Text ' Assuming you have a TextBox named txtEmail for the email input
Using connection As New SqlConnection(connectionString)
connection.Open()
Dim insertQuery As String = "INSERT INTO YourTable (Name, Email) VALUES (@Name, @Email)" ' Replace with your table and column names
Using cmd As New SqlCommand(insertQuery, connection)
cmd.Parameters.AddWithValue("@Name", name)
cmd.Parameters.AddWithValue("@Email", email)
Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
If rowsAffected > 0 Then
MessageBox.Show("Data inserted successfully.")
' Optionally, clear the input fields or perform other actions after successful insertion.
Else
MessageBox.Show("Data insertion failed.")
End If
End Using
End Using
End Sub
End Class
Comments
Post a Comment