Antes de utilizar uma base de dados Microsof Access(*.mdb) no site, recomendamos fortemente que leia o artigo Access versus MS-SQL.

Caso mesmo assim queira utilizar uma base Microsoft Access(*.mdb)no site por algum motivo especial, segue abaixo um simples exemplo de conexão.

<%@ Page Language="C#" ContentType="text/html" Debug="true" %>   <%@ import Namespace="System.Data"       %> <%@ import Namespace="System.IO"         %> <%@ import Namespace="System.Data.OleDb" %>   <html>     <script runat="server">       protected void Page_Load(Object Src, EventArgs E)     {         //Caminho da base na sua área de hospedagem         string caminhoBanco = "e://home//LOGINFTP//Dados//Nome_Banco.mdb";         //Consulta SQL a ser efetuada na base         string strSQL = "SELECT campo1, campo2 FROM tabela";           OleDbConnection conexao = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + caminhoBanco + ";Persist Security Info=False;");         try         {             conexao.Open();               OleDbCommand comando = new OleDbCommand(strSQL, conexao);             OleDbDataReader dr = comando.ExecuteReader();               Response.Write("SQL: " + strSQL + "<br>");             Response.Write("<table border='1'>");               //Imprime o nome de todos os campos retornados na consulta             for (int i = 0; i < dr.FieldCount; i++)             {                 Response.Write("<th>" + dr.GetName(i) + "</th>");             }               //Imprime os valores retornados na consulta             while (dr.Read())             {                 Response.Write("<tr>");                   for (int i = 0; i < dr.FieldCount; i++)                 {                     Response.Write("<td>" + dr.GetValue(i) + "</td>");                 }                   Response.Write("</tr>");             }               Response.Write("</table>");               Response.Write("<br><font color='blue'>Consulta efetuada com sucesso!</font>");               //Fecha a conexão do DataReader e depois do banco             dr.Close();             conexao.Close();         }         catch (Exception ex)         {             Response.Write("<br><font color='red'>Falha ao conectar-se na base de dados!</font><br>");             Response.Write(ex.ToString());         }         }     </script> </html>

 

Esse artigo ajudou você?

55 respostas para “Access em ASP.Net”

  1. James Smith

    Simply want to say your article is as astounding.
    The clearness in your post is just great and i could assume you’re an expert
    on this subject. Well with your permission let me to grab your feed to keep up to date with
    forthcoming post. Thanks a million and please continue the rewarding work.

    Responder
  2. Bryan Hardin

    I’ve been surfing online greater than three hours nowadays, but I by no means discovered any interesting article like yours.

    It’s beautiful worth sufficient for me. In my view, if all webmasters
    and bloggers made just right content as you did, the web will be
    a lot more useful than ever before.

    Responder
  3. compare staxyn and viagra

    compare staxyn and viagra

    compare staxyn and viagra

    Responder
  4. Kenneth Harvey

    Way cool! Some extremely valid points! I appreciate you writing this write-up plus the rest
    of the site is very good.

    Responder
  5. cialis and diharrea

    cialis and diharrea

    cialis and diharrea

    Responder
  6. Justin Scott

    I’ll right away grasp your rss feed as I can not to find your
    email subscription hyperlink or newsletter service.
    Do you have any? Please allow me understand so that I may
    just subscribe. Thanks.

    Responder
  7. son takes viagra

    son takes viagra

    son takes viagra

    Responder
  8. Margaret Neustadt

    Way cool! Some very valid points! I appreciate you penning this article and also the rest of the website is also really good.

    Responder
  9. Pamela Shrewsbury

    Hi would you mind sharing which blog platform you’re using?

    I’m going to start my own blog in the near future but I’m having
    a hard time choosing between BlogEngine/Wordpress/B2evolution and
    Drupal. The reason I ask is because your design seems different then most blogs and I’m looking for
    something completely unique. P.S My apologies for being off-topic but I had to ask!

    Responder
  10. Emily Spence

    I’ve been browsing online more than 3 hours today,
    yet I never found any interesting article like yours. It’s pretty worth enough for
    me. Personally, if all website owners and bloggers made good content as you did, the
    internet will be much more useful than ever before.

    Responder
  11. Francisco Phillips

    I am truly thankful to the holder of this web page who has shared this enormous post
    at at this place.

    Responder
  12. Danny Gardner

    Greetings from Ohio! I’m bored at work so I decided to browse your blog on my iphone during lunch break.
    I enjoy the information you present here and can’t wait to take a look when I get home.
    I’m amazed at how quick your blog loaded on my mobile ..

    I’m not even using WIFI, just 3G .. Anyways, very good blog!

    Responder
  13. Jean Burton

    This iss a toppic whicch is clse too myy heart… Beest wishes!
    Wheree arre your contwct deyails though?

    Responder
  14. how much cialis cost in mexico

    how much cialis cost in mexico

    how much cialis cost in mexico

    Responder
  15. Carolyn Foster

    I visited many web sites except the audio feature for audio songs present at
    this website is truly marvelous.

    Responder
  16. Rudolph Yun

    Only wanna remark on few general things, The website design and style is perfect, the written content is rattling superb :D.

    Responder
  17. viagra chemical name

    viagra chemical name

    viagra chemical name

    Responder
  18. Margaret Bonner

    I will right away seize your rss as I can not in finding your
    email subscription hyperlink or newsletter service. Do
    you have any? Please allow me recognize
    so that I may just subscribe. Thanks.

    Responder

Comente sobre este conteúdo! Escreva o que pensa, complemente, vamos discutir. O conhecimento é livre!