Private Sub SearchButton_Click(sender As Object, e As EventArgs)
Dim connectionString As String = "Data Source=(local);Initial Catalog=mydatabase;Integrated Security=True"
Using connection As New SqlConnection(connectionString)
connection.Open()
Dim sql As String = "DECLARE @input NVARCHAR(100) = @full_name" & vbCrLf &
"DECLARE @first_name NVARCHAR(50), @last_name NVARCHAR(50)" & vbCrLf &
vbCrLf &
"SET @first_name = LTRIM(LEFT(@input, CHARINDEX(' ', @input + ' ') - 1))" & vbCrLf &
"SET @last_name = LTRIM(RIGHT(@input, LEN(@input) - CHARINDEX(' ', @input)))" & vbCrLf &
vbCrLf &
"SELECT * FROM users WHERE first_name LIKE '%' + @first_name + '%' AND last_name LIKE '%' + @last_name + '%'"
Using command As New SqlCommand(sql, connection)
command.Parameters.AddWithValue("@full_name", fullNameTextBox.Text)
Dim adapter As New SqlDataAdapter(command)
Dim table As New DataTable()
adapter.Fill(table)
resultsDataGridView.DataSource = table
End Using
End Using
End Sub