Manuel Osorio

Manuel Osorio

  • NA
  • 2
  • 1.8k

Search records in table using stored procedure in VB.NET

Jun 30 2015 7:35 PM
Hello
I want to search records in table from sql server using a stored procedure. I have in my form a datagridview and a textbox and If it's possible filter records in datagridview while I write in the textbox. But especially I want to use a stored procedure, please :)
 
I fill my datagridview with this code :
Public Function CargarDatos() As DataTable
Dim cnn As New SqlConnection(Configuration.ConfigurationManager.ConnectionStrings("Conexion").ToString())
Dim cmd As New SqlCommand("ObtenerAccesorios", cnn)
cmd.CommandType = CommandType.StoredProcedure
cnn.Open()
If cmd.ExecuteNonQuery Then
Dim dt As New DataTable
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
Return dt
Else
Return Nothing
End If
cnn.Close()
End Function
 
The code in my windows form is:
 
Public Sub Cargar()
Dim func As New AccesoriosDAL
dt = func.CargarDatos
If dt.Rows.Count <> 0 Then
dgvListado.DataSource = dt
dgvListado.ColumnHeadersVisible = True
dgvListado.Columns("Estado").Visible = False
Linkinexistente.Visible = False
dgvListado.ClearSelection()
DesactivarEdiciongrid()
Else
dgvListado.DataSource = Nothing
dgvListado.ColumnHeadersVisible = False
Linkinexistente.Visible = True
End If
End Sub
 
Thank you so much and excuse me for my english :) 

Answers (1)