problem with a query
-
ok, so i'm trying to make a search page with listings of the results. here's the method: private bool Search( String strSearchString ) { bool ok = false; OleDbConnection connSearch = new OleDbConnection( System.Configuration.ConfigurationSettings.AppSettings[ "connString" ] ); OleDbCommand cmdSearchOpis = new OleDbCommand(); Common.NapuniCommand( cmdSearchOpis, "proc_Search", connSearch ); Common.NapraviParametar( cmdSearchOpis, "@SearchString", OleDbType.VarChar, strSearchString, "Input" ); try { connSearch.Open(); OleDbDataAdapter da = new OleDbDataAdapter( cmdSearchOpis ); DataTable dt = new DataTable(); da.Fill( dt ); if( dt.Rows.Count == 0 ) ok = false; else { rptSearchResultsTvrtke.DataSource = dt; rptSearchResultsTvrtke.DataBind(); ok = true; } da.Dispose(); dt.Dispose(); cmdSearchOpis.Dispose(); } catch( Exception ex ) { lblError.Text = ex.Message; } finally { connSearch.Close(); connSearch.Dispose(); } return ok; } so, when i use the following query ( with let's say, strSearchString = "a" ): SELECT * FROM tKorisnici WHERE Opis LIKE ("*" & [@SearchString] & "*") AND User=true; i get no results ( dt.Rows.Count = 0 ) Although when i run the query in Access 2002, i do get results. any other query with or without parameters works just fine and fills the repeater (rptSearchResultsTvrtke), and i'm pretty much stuck in here. plz help! :confused:
-
ok, so i'm trying to make a search page with listings of the results. here's the method: private bool Search( String strSearchString ) { bool ok = false; OleDbConnection connSearch = new OleDbConnection( System.Configuration.ConfigurationSettings.AppSettings[ "connString" ] ); OleDbCommand cmdSearchOpis = new OleDbCommand(); Common.NapuniCommand( cmdSearchOpis, "proc_Search", connSearch ); Common.NapraviParametar( cmdSearchOpis, "@SearchString", OleDbType.VarChar, strSearchString, "Input" ); try { connSearch.Open(); OleDbDataAdapter da = new OleDbDataAdapter( cmdSearchOpis ); DataTable dt = new DataTable(); da.Fill( dt ); if( dt.Rows.Count == 0 ) ok = false; else { rptSearchResultsTvrtke.DataSource = dt; rptSearchResultsTvrtke.DataBind(); ok = true; } da.Dispose(); dt.Dispose(); cmdSearchOpis.Dispose(); } catch( Exception ex ) { lblError.Text = ex.Message; } finally { connSearch.Close(); connSearch.Dispose(); } return ok; } so, when i use the following query ( with let's say, strSearchString = "a" ): SELECT * FROM tKorisnici WHERE Opis LIKE ("*" & [@SearchString] & "*") AND User=true; i get no results ( dt.Rows.Count = 0 ) Although when i run the query in Access 2002, i do get results. any other query with or without parameters works just fine and fills the repeater (rptSearchResultsTvrtke), and i'm pretty much stuck in here. plz help! :confused:
Have you tried using "%" instead of "*"? That's how it works on MS SQL Server, and I'm assuming you are using... Access 2003? try it. daniero
-
Have you tried using "%" instead of "*"? That's how it works on MS SQL Server, and I'm assuming you are using... Access 2003? try it. daniero
alright daniero, that was my problem... funny thing is that if i put % and run it in Access it gives a blank table. if i try to execute it through the code, i DO GET RESULTS!!! now, with * instead of % if i run it in Access i get results, but not through code... that's really odd if you ask me, but i'm glad u helped me solve this problem. thank you daniero, my savior of the day! :)
-
alright daniero, that was my problem... funny thing is that if i put % and run it in Access it gives a blank table. if i try to execute it through the code, i DO GET RESULTS!!! now, with * instead of % if i run it in Access i get results, but not through code... that's really odd if you ask me, but i'm glad u helped me solve this problem. thank you daniero, my savior of the day! :)
-
ok, so i'm trying to make a search page with listings of the results. here's the method: private bool Search( String strSearchString ) { bool ok = false; OleDbConnection connSearch = new OleDbConnection( System.Configuration.ConfigurationSettings.AppSettings[ "connString" ] ); OleDbCommand cmdSearchOpis = new OleDbCommand(); Common.NapuniCommand( cmdSearchOpis, "proc_Search", connSearch ); Common.NapraviParametar( cmdSearchOpis, "@SearchString", OleDbType.VarChar, strSearchString, "Input" ); try { connSearch.Open(); OleDbDataAdapter da = new OleDbDataAdapter( cmdSearchOpis ); DataTable dt = new DataTable(); da.Fill( dt ); if( dt.Rows.Count == 0 ) ok = false; else { rptSearchResultsTvrtke.DataSource = dt; rptSearchResultsTvrtke.DataBind(); ok = true; } da.Dispose(); dt.Dispose(); cmdSearchOpis.Dispose(); } catch( Exception ex ) { lblError.Text = ex.Message; } finally { connSearch.Close(); connSearch.Dispose(); } return ok; } so, when i use the following query ( with let's say, strSearchString = "a" ): SELECT * FROM tKorisnici WHERE Opis LIKE ("*" & [@SearchString] & "*") AND User=true; i get no results ( dt.Rows.Count = 0 ) Although when i run the query in Access 2002, i do get results. any other query with or without parameters works just fine and fills the repeater (rptSearchResultsTvrtke), and i'm pretty much stuck in here. plz help! :confused:
Hi, Can u do one thing, before putting the query in to your .cs file check that query executes well with MS SQL server instead of Access because i am bit scared that you are using "*", correct your query according to MSSQLserver query analyser. Then Try. :) DD Debasish Das(MBA), is a hardcore software solution provider, working in ESSPL (INDIA). Got 5 years of experience on various client server technologies like Visual Basic,.NET framework, Power Builder, Message Queue Server. And also posses sound knowledge in Quality Processes applied to software engineering. Quite often travels overseas to provide solutions to some fortune 100 clients. He can be reached with mr_debasishdas@hotmail.com or debasishd@esspl.com
-
alright daniero, that was my problem... funny thing is that if i put % and run it in Access it gives a blank table. if i try to execute it through the code, i DO GET RESULTS!!! now, with * instead of % if i run it in Access i get results, but not through code... that's really odd if you ask me, but i'm glad u helped me solve this problem. thank you daniero, my savior of the day! :)
I'm glad you've got it working :) daniero