Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Compare Textbox with SQL

$
0
0

Hello.

I have a Textbox. There the user inserts a text that it has to be compared with a DataBase.

If it's true it has to create a new GridView and show all the results of the consultation.

My code is now like that:

protectedvoidBBuscarfondo_Click(object sender,EventArgs e){SqlConnection con =newSqlConnection("Data Source=IMCJB150\\SQLEXPRESS; Initial Catalog=GestorInventario; Integrated Security=True");if(Page.IsValid){Paginas.SetActiveView(GridResultadoBuscar);string cadena ="SELECT * FROM Ordenadores o, Monitores m, Impresoras i, Escaneres e, Telefonos t, Proyectores p, Miscelanea mis WHERE NumSerie = '"+TBNumSerieBuscar.Text+"'";SqlCommand miComandoB =newSqlCommand(cadena, con);
            con.Open();SqlDataReaderLector= miComandoB.ExecuteReader();if(Lector.Read()==true){}else{Paginas.SetActiveView(Buscarotraopcion);}
            con.Close();}}

I want to look for NumSerie in all the tables of my DB and if in my DB is some product with that SerialNumber, it has to appear on my GridView.

My GV has this columns: ID, Type, Name, Model, Serial Number, Room and Inventary ID:

<asp:Viewrunat="server"ID="MuestraListado">

<h3> Resultado de la búsqueda con los parámetros introducidos: </h3><asp:GridViewrunat="server"ID="GVTabla"AutoGenerateColumns="False"DataSourceID="SQLDS"OnRowDataBound="GVTabla_RowDataBound"><Columns><asp:BoundFieldDataField="Id"HeaderText="Id"InsertVisible="False"/><asp:BoundFieldDataField="Tipo"HeaderText="Tipo"/><asp:BoundFieldDataField="Nombre"HeaderText="Nombre"/><asp:BoundFieldDataField="Modelo"HeaderText="Modelo"/><asp:BoundFieldDataField="NumSerie"HeaderText="Número de serie"/><asp:BoundFieldDataField="Sala"HeaderText="Sala"/><asp:BoundFieldDataField="IdInventario"HeaderText="Id Inventario"/></Columns></asp:GridView></asp:View>

I don't know how I have to create the gridview... thanks.


Viewing all articles
Browse latest Browse all 31927

Trending Articles