DBF를 C# 파일로 열고 MySQL 데이터베이스에 업로드하려고합니다. 지금 DBF 파일을 열려고하는데 다음과 같은 오류가 발생합니다.DBF 파일 읽기 : System.Data.OleDb.OleDbException
내 코드는 다음과 같습니다.
private void button2_Click(object sender, EventArgs e)
{
DirectoryInfo dir = new DirectoryInfo(Regex.Replace(textBox1.Text, @"\\", @"\\"));
foreach (FileInfo file in dir.GetFiles())
{
MessageBox.Show(file.Name);
string strAccessConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dir + file.Name;
string strAccessSelect = "SELECT * FROM "+file.Name.Substring(0,file.Name.Length-4);
DataSet myDataSet = new DataSet();
OleDbConnection myAccessConn = null;
try
{
myAccessConn = new OleDbConnection(strAccessConn);
}
catch (Exception ex)
{
Console.WriteLine("Error: Failed to create a database connection. \n{0}", ex.Message);
return;
}
try
{
OleDbCommand myAccessCommand = new OleDbCommand(strAccessSelect, myAccessConn);
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(myAccessCommand);
myAccessConn.Open();
myDataAdapter.Fill(myDataSet);
}
catch (Exception ex)
{
Console.WriteLine("Error: Failed to retrieve the required data from the DataBase.\n{0}", ex.Message);
return;
}
finally
{
myAccessConn.Close();
}
}
}
난 단지 파일 이름으로 처음 MessageBox
를 얻을 후 오류가 발생합니다.
스택 추적을 게시하십시오. – JNYRanger
음, 연결하려는 Dbase/Foxpro 데이터베이스가 있습니까? foxpro dbf에서 데이터 소스가 폴더 이름을 확인해야한다고 생각합니다. https://www.connectionstrings.com/dbf-foxpro/ – bansi
user908759 : 어떤 문제가 있습니까? try ... catch 블록을 제거하여 어느 구문에서 어떤 오류 유형 및 msg를 얻었는지 확인하십시오. –