Alex Calidguid

Alex Calidguid

  • 1.6k
  • 192
  • 5.2k

Can't load data from .dbf file into Datagridview using c#

Dec 15 2013 4:03 AM
Hello guys,

I have some problem of loading data from .dbf file into datagrideview using c#

here's the first code that I written

try
            {
                
                string odbcConnect = @"Provider = Microsoft.ACE.OLEDB.12.0; Data Source = "+ lblpath.Text + "; Entended Properties = dDASE IV; User ID=;Password=";
               
               
                OleDbConnection con = new OleDbConnection();
                con.ConnectionString = odbcConnect;
                con.Open();
                string connecData = "select * from Attendance";

                OleDbDataAdapter da = new OleDbDataAdapter(connecData, con);

                da.Fill(dsData);
                con.Close();
                DgvGetData.DataSource = dsData.Tables[0];

            } catch(OleDbException exp){
                MessageBox.Show("Error: " + exp.Message);
            
            }

the second code:

void Loaddata()
        {
            OdbcConnection oConn = new OdbcConnection();
            oConn.ConnectionString = ("Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277; Dbq=D:\\Attendance;");
           Collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO;";
            oConn.Open();
            OdbcCommand oCmd = oConn.CreateCommand();
            oCmd.CommandText = @"SELECT badgenon,badgename empno, date FROM Attendance.dbf";
            DataTable dt = new DataTable();
            dt.Load(oCmd.ExecuteReader());
            oConn.Close();

            DgvGetData.DataSource = dt; 
        
        }

Its gave me nothing just an errors

Thanks you,

Answers (1)