Llamar Datos
Publicado por Pinky (110 intervenciones) el 24/07/2010 22:35:46
Hola amigos del foro mi consulta es la siguinete pretendo llamar los datos a través de una caja de texto solamente ingresando la primera letra del nombre del proveedor a través de la sentencia Like me arroje todos los nombres de los proveedores que empicen con esa letra por ej. "a", y que me los muestre en una grilla, hago mención que utiixo el VB.2008 y la grilla la trabajo con el Gridview este es el código que estoy utilizando actualmente.
Imports System.Data
Imports System.Data.SqlClient
Imports System.Xml
Partial Class Frmconsulproveedor
Inherits System.Web.UI.Page
Public conn As New SqlClient.SqlConnection("data source = (local);Initial Catalog=Sistema;Integrated Security=True")
Public ds As New Data.DataSet
Public da As Data.SqlClient.SqlDataAdapter
Public edit_mode As Boolean = False
Sub llenar_grilla(Optional ByVal opcion As String = "")
Dim valor As String
If opcion = "" Then
If CheckBox1.Text = "---" Then
valor = TXTPROVEEDOR.Text
Else
valor = CheckBox1.Text
End If
Else
valor = opcion
End If
Try
da = New Data.SqlClient.SqlDataAdapter("Select * From Proveedores where Nombre_Proveedor = '" + valor.ToString + "' ", conn)
da.MissingSchemaAction = MissingSchemaAction.AddWithKey
Dim builder As Data.SqlClient.SqlCommandBuilder = New SqlClient.SqlCommandBuilder(da)
Dim ds As New DataSet
da.Fill(ds, "Grilla")
Dim vista As DataView = New DataView(ds.Tables("Grilla"), " ", "Nombre_Proveedor asc", DataViewRowState.CurrentRows)
Grilla.DataSource = vista
Grilla.DataBind()
Session.Add("tabla", ds)
Session.Add("cmd", builder)
Catch ex As Data.SqlClient.SqlException
MsgBox("Error:" & vbCrLf & ex.Message, MsgBoxStyle.Critical, "Sistema")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
conn.Open()
If Not Me.Page.IsPostBack Then
llenar_grilla()
End If
Dim HOY As Date
Dim Fecha As String
HOY = Now
Fecha = Format(HOY, "dd/MM/yyyy")
LABELFECHA.Text = Fecha
LABELFECHA.Text = Fecha
TXTPROVEEDOR.Focus()
End Sub
Protected Sub TXTPROVEEDOR_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TXTPROVEEDOR.TextChanged
If TXTPROVEEDOR.Text = "" Then
da = New SqlDataAdapter("select * from Proveedores", conn)
ds = New DataSet
da.Fill(ds, "Proveedores")
Grilla.DataSource = ds
Grilla.DataMember = "Proveedores"
Else
da = New SqlDataAdapter("select Nombre_Proveedor,Rut_Proveedor from Proveedores where Nombre_Proveedor like '% " & TXTPROVEEDOR.Text.Trim & "%'; ", conn)
ds = New DataSet
da.Fill(ds, "Proveedores")
Grilla.DataSource = ds
Grilla.DataMember = "Proveedores"
End If
End Sub
ojala que me puedan ayudar uy mencionarme en done esta el error que estoy cometiendo, desde ya muchas gracias.
Imports System.Data
Imports System.Data.SqlClient
Imports System.Xml
Partial Class Frmconsulproveedor
Inherits System.Web.UI.Page
Public conn As New SqlClient.SqlConnection("data source = (local);Initial Catalog=Sistema;Integrated Security=True")
Public ds As New Data.DataSet
Public da As Data.SqlClient.SqlDataAdapter
Public edit_mode As Boolean = False
Sub llenar_grilla(Optional ByVal opcion As String = "")
Dim valor As String
If opcion = "" Then
If CheckBox1.Text = "---" Then
valor = TXTPROVEEDOR.Text
Else
valor = CheckBox1.Text
End If
Else
valor = opcion
End If
Try
da = New Data.SqlClient.SqlDataAdapter("Select * From Proveedores where Nombre_Proveedor = '" + valor.ToString + "' ", conn)
da.MissingSchemaAction = MissingSchemaAction.AddWithKey
Dim builder As Data.SqlClient.SqlCommandBuilder = New SqlClient.SqlCommandBuilder(da)
Dim ds As New DataSet
da.Fill(ds, "Grilla")
Dim vista As DataView = New DataView(ds.Tables("Grilla"), " ", "Nombre_Proveedor asc", DataViewRowState.CurrentRows)
Grilla.DataSource = vista
Grilla.DataBind()
Session.Add("tabla", ds)
Session.Add("cmd", builder)
Catch ex As Data.SqlClient.SqlException
MsgBox("Error:" & vbCrLf & ex.Message, MsgBoxStyle.Critical, "Sistema")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
conn.Open()
If Not Me.Page.IsPostBack Then
llenar_grilla()
End If
Dim HOY As Date
Dim Fecha As String
HOY = Now
Fecha = Format(HOY, "dd/MM/yyyy")
LABELFECHA.Text = Fecha
LABELFECHA.Text = Fecha
TXTPROVEEDOR.Focus()
End Sub
Protected Sub TXTPROVEEDOR_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TXTPROVEEDOR.TextChanged
If TXTPROVEEDOR.Text = "" Then
da = New SqlDataAdapter("select * from Proveedores", conn)
ds = New DataSet
da.Fill(ds, "Proveedores")
Grilla.DataSource = ds
Grilla.DataMember = "Proveedores"
Else
da = New SqlDataAdapter("select Nombre_Proveedor,Rut_Proveedor from Proveedores where Nombre_Proveedor like '% " & TXTPROVEEDOR.Text.Trim & "%'; ", conn)
ds = New DataSet
da.Fill(ds, "Proveedores")
Grilla.DataSource = ds
Grilla.DataMember = "Proveedores"
End If
End Sub
ojala que me puedan ayudar uy mencionarme en done esta el error que estoy cometiendo, desde ya muchas gracias.
Valora esta pregunta


0