Does the VWD 2008 Express edition bind *.Accdb databases?
![]() |
0 |
![]() |
Ofcourse it can bind ... but you must use different data provider .
String ConnectionStringSampleDB = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\\personalinfo.accdb;Persist Security Info=True";
use this connection string ... its work for me ,
total sample code ...is here Design part
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>WelCome || Sample Database connetion Between ASP.NET C# and MS Access Database </title> <style type="text/css"> .style1 { width: 100%; } </style> </head> <body> <form id="form1" runat="server"> <div> <table cellpadding="0" cellspacing="0" class="style1"> <tr> <td> </td> <td style="width: 800px"> </td> <td> </td> </tr> <tr> <td> </td> <td style="width: 800px"> <table cellpadding="5" cellspacing="5" class="style1"> <tr> <td colspan="3"> <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="20pt" ForeColor="#009933" Text="Personal Information"></asp:Label> <hr /> </td> </tr> <tr> <td style="width: 30%"> <asp:Label ID="Label2" runat="server" Text="Name :"></asp:Label> </td> <td style="width: 50%"> <asp:TextBox ID="txtName" runat="server" Width="80%"></asp:TextBox> </td> <td style="width: 20%"> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtName" ErrorMessage="Name Cannot be blank"></asp:RequiredFieldValidator> </td> </tr> <tr> <td style="width: 30%"> <asp:Label ID="Label3" runat="server" Text="Email :"></asp:Label> </td> <td style="width: 50%"> <asp:TextBox ID="txtEmail" runat="server" Width="80%"></asp:TextBox> </td> <td style="width: 20%"> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtEmail" ErrorMessage="Email cannot be blank"></asp:RequiredFieldValidator> </td> </tr> <tr> <td style="width: 30%"> <asp:Label ID="Label4" runat="server" Text="Phone :"></asp:Label> </td> <td style="width: 50%"> <asp:TextBox ID="txtPhone" runat="server" Height="22px"></asp:TextBox> </td> <td style="width: 20%"> <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtPhone" ErrorMessage="Phone cannot be blank"></asp:RequiredFieldValidator> </td> </tr> <tr> <td style="width: 30%; vertical-align: top;"> <asp:Label ID="Label5" runat="server" Text="Address :"></asp:Label> </td> <td style="width: 50%"> <asp:TextBox ID="txtAdd" runat="server" Height="50px" TextMode="MultiLine" Width="80%"></asp:TextBox> </td> <td style="width: 20%; vertical-align: top;"> <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtAdd" ErrorMessage="Address cannot be blank"></asp:RequiredFieldValidator> </td> </tr> <tr> <td style="width: 30%"> <asp:Label ID="Label6" runat="server" Text="Job :"></asp:Label> </td> <td style="width: 50%"> <asp:TextBox ID="txtJob" runat="server"></asp:TextBox> </td> <td style="width: 20%"> <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="txtJob" ErrorMessage="Job cannot be blank"></asp:RequiredFieldValidator> </td> </tr> <tr> <td style="width: 30%; vertical-align: top;"> <asp:Label ID="Label7" runat="server" Text="Comments :"></asp:Label> </td> <td style="width: 50%"> <asp:TextBox ID="txtComments" runat="server" Height="68px" TextMode="MultiLine" Width="80%"></asp:TextBox> </td> <td style="width: 20%; vertical-align: top;"> </td> </tr> <tr> <td colspan="3"> <asp:Button ID="Clear" runat="server" BorderStyle="Dotted" CausesValidation="False" Font-Bold="True" Text="Clear" Width="140px" onclick="Clear_Click" /> <asp:Label ID="lblmgs" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label> <hr /></td> </tr> <tr> <td colspan="3"> <table cellpadding="2" class="style1"> <tr> <td style="width: 20%"> <asp:Button ID="btnInsert" runat="server" Font-Bold="True" Text="Insert" Width="98%" BorderStyle="Dotted" onclick="btnInsert_Click" /> </td> <td style="width: 20%"> <asp:Button ID="btnUpdate" runat="server" Font-Bold="True" Text="Update" Width="98%" BorderStyle="Dotted" onclick="btnUpdate_Click" /> </td> <td style="width: 20%"> <asp:Button ID="btnDelete" runat="server" Font-Bold="True" Text="Delete" Width="98%" BorderStyle="Dotted" CausesValidation="False" onclick="btnDelete_Click" /> </td> <td style="width: 20%"> <asp:TextBox ID="txtSearch" runat="server" Width="98%"></asp:TextBox> </td> <td style="width: 20%"> <asp:Button ID="btnSearch" runat="server" Font-Bold="True" Text="Search" Width="98%" BorderStyle="Dotted" CausesValidation="False" onclick="btnSearch_Click" /> </td> </tr> </table> </td> </tr> </table> </td> <td> </td> </tr> <tr> <td> </td> <td style="width: 800px"> <asp:Label ID="Label8" runat="server" Font-Bold="True" Text="Total Record :"></asp:Label> </td> <td> </td> </tr> <tr> <td> </td> <td style="width: 800px"> <asp:GridView ID="GridView1" runat="server" Width="100%"> <AlternatingRowStyle BorderStyle="Solid" /> </asp:GridView> </td> <td> </td> </tr> <tr> <td> </td> <td style="width: 800px"> </td> <td> </td> </tr> </table> </div> </form> </body> </html>Code behindusing System; using System.Configuration; using System.Data; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Data.OleDb; public partial class _Default : System.Web.UI.Page { //declare Connection string String ConnectionStringSampleDB = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\\personalinfo.accdb;Persist Security Info=True"; protected void Page_Load(object sender, EventArgs e) { LoadData();//call loaddata } protected void btnInsert_Click(object sender, EventArgs e) { OleDbConnection cn = new OleDbConnection(ConnectionStringSampleDB);//create connection cn.Open();//Open connection string strSave = "insert into Info_TBL Values("; strSave = strSave + "'" + txtName.Text + "'"; strSave = strSave + ",'" + txtEmail.Text + "'"; strSave = strSave + ",'" + txtPhone.Text + "'"; strSave = strSave + ",'" + txtAdd.Text + "'"; strSave = strSave + ",'" + txtJob.Text + "'"; strSave = strSave + ",'" + txtComments.Text + "')"; OleDbCommand cmd = new OleDbCommand(strSave, cn);//create command cmd.ExecuteNonQuery();//Finally execute cn.Close();//connection close lblmgs.Text = "Succesfully Insert Data"; LoadData(); Clear_Data(); } protected void btnUpdate_Click(object sender, EventArgs e) { OleDbConnection cn = new OleDbConnection(ConnectionStringSampleDB); cn.Open();//Open connection string strUpdate = "update Info_TBL set Email = '" + txtEmail.Text + "',Phone ='" + txtPhone.Text + " ',Address ='" + txtAdd.Text + "',Job ='" + txtJob.Text + "'where Name ='" + txtName.Text + "'"; OleDbCommand sqlCmd = new OleDbCommand(strUpdate, cn); sqlCmd.ExecuteNonQuery(); lblmgs.Text = "Update successfully"; cn.Close(); LoadData(); } protected void btnDelete_Click(object sender, EventArgs e) { if (txtName.Text == "") { lblmgs.Text = "You need to Put Name!!!"; } else { OleDbConnection cn = new OleDbConnection(ConnectionStringSampleDB); cn.Open();//Open connection string strDel = "Delete from Info_TBL where Name='" + txtName.Text + "'"; OleDbCommand oleCmd = new OleDbCommand(strDel, cn); oleCmd.ExecuteNonQuery(); lblmgs.Text = "Deleted successfully"; cn.Close(); LoadData(); } } protected void btnSearch_Click(object sender, EventArgs e) { OleDbConnection cn = new OleDbConnection(ConnectionStringSampleDB); cn.Open();//Open connection string strserch = "Select * from Info_TBL Where Name='" + txtSearch.Text + "'"; OleDbDataAdapter da = new OleDbDataAdapter(strserch, cn);// create data adapter DataTable dt = new DataTable();//declare data table DataSet ds = new DataSet();// declare a data set da.Fill(ds, "Info_TBL");// dt = ds.Tables["Info_TBL"]; if (dt.Rows.Count > 0)//search data is present or not { txtName.Text = dt.Rows[0]["Name"].ToString(); txtEmail.Text = dt.Rows[0]["Email"].ToString(); txtPhone.Text = dt.Rows[0]["Phone"].ToString(); txtAdd.Text = dt.Rows[0]["Address"].ToString(); txtJob.Text = dt.Rows[0]["Job"].ToString(); txtComments.Text = dt.Rows[0]["Comments"].ToString(); } else { lblmgs.Text = "Data Not Found"; } cn.Close(); LoadData(); } void LoadData() { OleDbConnection cn = new OleDbConnection(ConnectionStringSampleDB); cn.Open();//Open connection string strserch = "Select * from Info_TBL"; OleDbDataAdapter da = new OleDbDataAdapter(strserch, cn); DataSet ds = new DataSet(); da.Fill(ds, "Info_TBL");// load data into adadpter GridView1.DataSource = ds; GridView1.DataBind();// finally bind in datagrid } void Clear_Data() { txtName.Text = string.Empty; txtEmail.Text = string.Empty; txtPhone.Text = string.Empty; txtJob.Text = string.Empty; txtAdd.Text = string.Empty; txtComments.Text = string.Empty; } protected void Clear_Click(object sender, EventArgs e) { Clear_Data(); } }
Md. Parves Kawser
Please remember to click “Mark as Answer” on the post that helps you.
![]() |
0 |
![]() |