0

如何在 MS Access 中导出 gridview?

我正在使用此代码

 Response.ClearContent();
 Response.Buffer = true;
 Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Details.mdb"));
 Response.ContentType = "application/ms-access";
 StringWriter sw = new StringWriter();
 HtmlTextWriter htw = new HtmlTextWriter(sw);
 DataGrid dGrid = new DataGrid();
 dGrid.AllowPaging = false;
 dGrid.DataSource = dt;
 dGrid.DataBind();
 dGrid.RenderControl(htw);
 Response.Write(sw.ToString());
 Response.End();

但是这个代码文件没有在 MS 访问中打开我该怎么办?

4

1 回答 1

-1

我使用以下代码使用 C# 来打开 MS 访问数据库:

在此处输入代码

    ADOX.Catalog cat = new ADOX.Catalog();
    ADOX.Table table = new ADOX.Table();


    table.Name = "Table1";
    table.Columns.Append("PartNumber", ADOX.DataTypeEnum.adVarWChar, 6); 
    table.Columns.Append("AnInteger", ADOX.DataTypeEnum.adInteger, 10); 
    try
    {
        cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=d:/m2.accdb;" + "Jet OLEDB:Engine Type=5");
        cat.Tables.Append(table);
        OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;" + "Data Source=d:/m2.accdb");
       conn.Open();

             OleDbCommand cmd = new OleDbCommand();
             cmd.Connection = conn;

             cmd.CommandText = "INSERT INTO Table1

([PartNumber],[AnInteger]) 值 (@FirstName,@LastName)";

             cmd.Parameters.Add("@FirstName", 

OleDbType.VarChar).Value = "neha";

             cmd.Parameters.Add("@LastName", 

OleDbType.VarChar).Value = 20;

             cmd.ExecuteNonQuery();

            conn.Close();                                 

    }
    catch (Exception ex)
    {
        result = false;
    }
    cat = null;
于 2013-07-25T06:19:50.807 回答