I'm creating a system that will read a xls
file, delete the data from a dbf
file, and then include all the xls
records in the table.
However, this system is an intermediate system, since dbf
data is used in a VB system.
The intermediate system is querying the xls
, writing the data to a DataTable
, it is deleting the dbf
data (it is even giving "PACK" to confirm the deletion of the data) and inserts new records in the file .
I'm using the DBF Commander to check if the data is actually there. But when I open the system and I generate a query, it does not return any records and also does not allow me to insert new records.
I am putting the deletion code, because I have verified that even without inserting a record by my system, leaving dbf
clean, I can not include new records
private void btnDeletar_Click(object sender, EventArgs e)
{
// Pergunta se deseja continuar
if (clsGeneric.MsgDialog("Você está prestes a deletar a tabela. Deseja continuar?", "Cuidado!", clsGeneric.DialogType.Question) == DialogResult.Yes)
{
// Instâncias
string vStrFileTree;
string vSql;
OleDbConnection conn;
OleDbCommand com;
vStrFileTree = edtPathDBF.Text;
// Busca do diretório
string strDirectoryPath = Path.GetDirectoryName(vStrFileTree);
string strTable = vStrFileTree.Replace(strDirectoryPath, "");
strTable = strTable.Replace("\", "");
// Conexão para a alterar a flag de "registro deletado" do DBF [Não Exclui os dados]
conn = new OleDbConnection(clsConnection.strConnectDBF(strDirectoryPath, "EXCLUSVE=YES;"));
conn.Open();
try
{
com = new OleDbCommand();
com.Connection = conn;
vSql = "DELETE FROM " + strTable;
com.CommandText = vSql;
com.ExecuteNonQuery();
}
finally
{
conn.Close();
conn = null;
com = null;
}
// Regerando as conexões, fazendo o PACK do arquivo DBF [PACK - Exclusão Permanente dos dados deletados]
conn = new OleDbConnection(clsConnection.strConnectDBF(strDirectoryPath, "EXCLUSVE=YES;"));
conn.Open();
try
{
com = new OleDbCommand();
com.Connection = conn;
com.CommandText = "PACK " + strTable;
com.ExecuteNonQuery();
}
finally
{
conn.Close();
conn = null;
com = null;
}
}
getDBFTable(grdImpDBF, edtPathDBF, false);
}
The following is the string string code:
public static string strConnectDBF(string Path, string Extended = "")
{
vStrConn = "Provider=VFPOLEDB.1;";
vStrConn = vStrConn + "Data Source=" + Path + ";";
if (Extended != "")
{
vStrConn = vStrConn + Extended;
}
return vStrConn;
}