http://dotnet.aspx.cc/ShowDetail.aspx?id=ZP4KXO6X-I697-4I4R-YKYB-6KFVPBC5JJPU

解决方案 »

  1.   

    /// <summary>
    /// 返回指定表的结构
    /// </summary>
    /// <param name="varTableName"></param>
    /// <returns></returns>
    public static DataTable GetTheTable(string varTableName)
    {
    DataTable dt = new DataTable(); DataSet ds = new DataSet(); OleDbDataAdapter Odb = new OleDbDataAdapter("select * from " + varTableName,Con);
    try
    {
    Con.Open();
    Odb.FillSchema(ds,SchemaType.Source,varTableName);
    }
    catch(Exception ex)
    {
    throw ex;
    }
    finally
    {
    Con.Close();
    }
    return ds.Tables[varTableName];
    } 通过这个方法返回的表结构包含了主键信息
    你可以通过
    dt.PrimaryKey来访问他的主键数组
      

  2.   

    注明:必须要用OleDb连接OleDbConnection Con = new OleDbConnection(DBAccess.ConString)