Getting Value from Mdb

Asked By Doğancan Kefeli
05-Sep-10 04:53 AM
Earn up to 0 extra points for answering this tough question.
Hi,
I m try to get a table from Microsoft Access.But, When i m try to get value with like method, i can't get table value.Null table returns.

For example My table; TABLE NAME : INFO
| ID  | Name  | Adress   | checked
 1   John    google.com   true

Mysql command for getting John : SELECT name FROM INFO WHERE 1=1 AND Name LIKE 'J*';
My c# code:
DataTable dt = Dbconnect(sql);
datagrid.source=dt;

private DataTable Dbconnect(string command)
    {
      DataTable dtParameters = new DataTable();
      string pathProject = "Var.mdb";
      string sCnstr = @"Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Data Source=" + pathProject +
     ";Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security info=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1";
      OleDbConnection conn = new OleDbConnection(sCnstr);
      try
      {
      conn.Open();
      OleDbDataAdapter my = new OleDbDataAdapter(command, conn);
      my.Fill(dtParameters);
      return dtParameters;
      }
      finally
      {

      conn.Close();
      conn.Dispose();

      }

 ALSO

if i use sql command like "select * from INFO", i get table and value. This show that there is no problem about connection , Then i try to check query bulding in MS access , sql command returns correct result. But, in c# , result is not returned.

  re: Getting Value from Mdb

Mohan Raj Aryal replied to Doğancan Kefeli
05-Sep-10 06:28 AM
Should this be type?

SELECT name FROM INFO WHERE 1=1 AND Name LIKE 'J*';

instead of 

SELECT name FROM INFO WHERE ID=1 AND Name LIKE 'J*';

  re: Getting Value from Mdb

Mohan Raj Aryal replied to Doğancan Kefeli
05-Sep-10 06:30 AM
One more correction: 

SELECT name FROM INFO WHERE ID=1 AND Name LIKE 'J%';

  re: Getting Value from Mdb

Doğancan Kefeli replied to Mohan Raj Aryal
05-Sep-10 06:33 AM
Thanks for reply;
but i want to get name which begins with J so 1=1 is not important. While i am checking  code(SELECT name FROM INFO WHERE 1=1 AND Name LIKE 'J*'; ) at MS access query builder , i get correct result. In C# tableset, i can't see any row or colum. This is very intresting.. While i try this code: SELECT * FROM INFO, i get all colums :(
  re: Getting Value from Mdb
Doğancan Kefeli replied to Mohan Raj Aryal
05-Sep-10 07:36 AM
Thank you Mr. Mohan. I fix problem which is using "(" like that SELECT * FROM name WHERE  ( NAME LIKE 'J%')
Create New Account