环境:  vs.net2005(c#-winfrom) windows2003server foxpro6.0
需求: 提取 4个 相同结构的数据表中数据,并合并显示.(4个数据表中的数据不同^-^)
实现: 用一个OpenFileDialog 4个文本框 5个按钮 
问题: 提取4个数据表数据时,提取出的数据为用OpenFileDialog最后选定的表的数据,提取4次.
      而不是每个表提取一次.连接字符串:
private string connectionString =
"BackgroundFetch=Yes;Collate=Machine;Exclusive=No;" +
"UID=;SourceType=DBF;Driver=Driver para o Microsoft Visual FoxPro;SourceDB=";//后面跟数据表存放的目录
窗口的代码:
DataTable alltable = null;//数据合并用
string message = "";//错误信息
ArrayList alist = new ArrayList();//存放数据表 序列for (int i = 0; i < Program.nameS.DataNameList.Count; i++)//遍历取到的数据表路径
{
Database db = new Database();//数据提取基本类库 string DataName = Program.nameS.DataNameList[i].ToString().Trim();//数据表路径<<---提取出的数据路径无误 //文件是否存在
if (File.Exists(DataName))
{
Application.DoEvents();
string tableName = Path.GetFileNameWithoutExtension(DataName);//表名
string connPath = connectionString +Path.GetDirectoryName(DataName) + ";";//连接字符创 OdbcConnection con = db.GetConnectionA(connPath);//连接获取

string sqlWhere = "" + " select xm,dw,xb,zw,lb,ms,bh,'" + i.ToString() + 
                                  "' xx,'" + DataName + "' hh from " + tableName;
DataTable dt = db.GetTable(sqlWhere, con);//数据提取<<----就是这里提取出的数据不对 
alist.Add(dt); con = null;
Application.DoEvents();
}
else
{
message += "\r\n文件[" + DataName + "]不存在,请您确认~!";
}
}if (message.Trim() != "")
{
MessageBox.Show("错误信息:" + message);
}基础类库(Database)的代码:
/// <summary>
/// 连接VF数据库
/// </summary>
/// <returns></returns>
public OdbcConnection GetConnectionA(string strcon)
{
OdbcConnection Con = new OdbcConnection();

Con.ConnectionString=strcon; try
{
Con.Open();
Con.Close();
}
catch(Exception ex)
{
if (Con.State != ConnectionState.Closed)
{
Con.Close();
}
Con = null;
} return Con;
}
/// <summary>
/// 查询数据
/// </summary>
/// <param name="sql"></param>
public DataTable GetTable(string sql, OdbcConnection Con)
{
OdbcDataAdapter Adapter=null;
DataTable table = new DataTable(); try
{
Con.Open();
Adapter = new System.Data.Odbc.OdbcDataAdapter(sql, Con);
Adapter.Fill(table);
Con.Close(); }
catch(Exception ex)
{
if (Con.State != ConnectionState.Closed)
{
Con.Close();
}
table = null;
}
Adapter.Dispose(); return table;
}
代码中删掉了一些,错误验证,因为太长了,不方便阅读~!
个人崩溃中ing.... 请大家帮帮忙吧~!