2 Replies - 829 Views - Last Post: 08 March 2011 - 03:10 PM Rate Topic: -----

#1 Ahmedn1  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 23
  • View blog
  • Posts: 556
  • Joined: 04-August 09

Oledb Command execution problems

Posted 08 March 2011 - 02:05 PM

I'm developing an application that was dealing with SQL Server 2008 database
it was working perfect

I wanted to make a lite version of it using Access database to be used on weak PCs
So I changed the connection string as this:

internal static string dataPath = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=BPAS.accdb";


I changed all objects from SqlClient to Oledb

/*
        SqlDataAdapter da = new SqlDataAdapter();
        SqlCommand cm = new SqlCommand();
        SqlConnection cn = new SqlConnection(Program.dataPath);//HeMa
        DataSet ds;
        SqlDataReader reader;
        SqlDataReader _dr;
        */

        OleDbDataAdapter da = new OleDbDataAdapter();
        OleDbCommand cm = new OleDbCommand();
        OleDbConnection cn = new OleDbConnection(Program.dataPath);//HeMa
        DataSet ds;
        OleDbDataReader reader;
        OleDbDataReader _dr;



I changed date search in queries from "where [date] = '" + dateObject + "'"
to "where [date] = #" + dateObject + "#"

I changed the like parameter from % to *

I already opened the access database and executed the queries in the applications myself and they all returned the expected results

but in the application each time it returns 0 rows
NO EXCEPTIONS

Just 0 rows

here is the connection declaration

cm.Connection = cn;
            cm.CommandTimeout = 28800;
            cm.CommandType = CommandType.Text;
            try
            {
                cn.Open();
            }
            catch (Exception ex) { MessageBox.Show(ex.Message, "Error : [P707]", MessageBoxButtons.OK, MessageBoxIcon.Warning); }



and here is one example of my queries


                    cm.CommandText = "select  * from Results where [Name] like '*" + txtSearch.Text + "*'";

            //da = new SqlDataAdapter(cm);
            da = new OleDbDataAdapter(cm);
            ds = new DataSet();
            da.Fill(ds, "Results");
            dgSearch.DataSource = ds.Tables["Results"];
            try
            {
                cn.Close();
            }
            catch { }



this always returns 0 rows

Is This A Good Question/Topic? 0
  • +

Replies To: Oledb Command execution problems

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9048
  • View blog
  • Posts: 33,971
  • Joined: 12-June 08

Re: Oledb Command execution problems

Posted 08 March 2011 - 02:31 PM

My guess is your select statement's where clause is killing you.

"select  * from Results where [Name] like '*" + txtSearch.Text + "*'"


Try making the * into %; assuming you are trying to use the * as wildcards on both ends.
http://msdn.microsof...y/ms179859.aspx


"select * from Results where [Name] like '%" + txtSearch.Text + "%'"

Better yet - use a string.format statement!

 String.Format("select  * from Results where [Name] like '%{0}%'", txtSearch.Text)

Was This Post Helpful? 1
  • +
  • -

#3 Ahmedn1  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 23
  • View blog
  • Posts: 556
  • Joined: 04-August 09

Re: Oledb Command execution problems

Posted 08 March 2011 - 03:10 PM

View Postmodi123_1, on 08 March 2011 - 02:31 PM, said:

Better yet - use a string.format statement!

 String.Format("select  * from Results where [Name] like '%{0}%'", txtSearch.Text)


Thank you very much this helped alot
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1