Hello friends! I'm writing a program that is connected to a mdf database and i need to query the database, but I have tried several ways to do it but without success :( !
This is my code:
string Query = null; SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True"); con.Open(); Query = txtSearch.Text; SqlCommand comm = new SqlCommand("SELECT SUCURSAL_PRODUCTO.SUCURSAL_idSucursal, SUCURSAL_PRODUCTO.PRODUCTO_idProducto, SUCURSAL_PRODUCTO.cantidadStock, PRODUCTO.idProducto, PRODUCTO.titulo, PRODUCTO.autor, PRODUCTO.precio, SUCURSAL_PRODUCTO.cantidadStock AS Expr1," + "SUCURSAL_PRODUCTO.SUCURSAL_idSucursal AS Expr2 " + "FROM SUCURSAL_PRODUCTO INNER JOIN PRODUCTO ON SUCURSAL_PRODUCTO.PRODUCTO_idProducto = PRODUCTO.idProducto "+ "WHERE (SUCURSAL_PRODUCTO.SUCURSAL_idSucursal = 2)", con); //SqlCommand comm = new SqlCommand("SELECT * FROM PRODUCTO", con); DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(comm); da.Fill(dt); //lstData.DataContext = dt.DefaultView; Query = comm.ExecuteScalar() as string; //Query = (string)comm.ExecuteScalar(); lstData.DataContext = Query;
The main query works if i execute it from a button(but that displays all the data) that's why i need to filter the results on my app, the data is populated on a listView called lstData.
If you need anything else please let me now.
P.S. I'm using WPF 2010
Thanks in advanced.