
September 15th, 2005, 07:04 PM
|
|
Registered User
|
|
Join Date: Jan 2003
Posts: 21
Time spent in forums: 54 m 25 sec
Reputation Power: 0
|
|
|
asp.net, c#, ms access; where's the problem?
Hello guys
I have litle problem when trying to load data into datagrid from ms access database,
here is code of index.aspx:
Code:
<%@ Page language="c#" Codebehind="index.aspx.cs" AutoEventWireup="false" Inherits="Nable_Soft.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:datagrid id="DataGrid1" runat="server" PageSize="3" AllowPaging="True" AutoGenerateColumns="False"
AllowSorting="True" BackColor="#E0E0E0" BorderColor="Black" BorderStyle="Dashed" Font-Names="Arial"
AllowCustomPaging="True">
<Columns>
<asp:BoundColumn DataField="lastname" SortExpression="FName" HeaderText="First Name"></asp:BoundColumn>
<asp:BoundColumn DataField="firstname" SortExpression="LName" HeaderText="Last Name"></asp:BoundColumn>
</Columns>
</asp:datagrid></form>
</body>
</HTML>
and this is the code of behind page index.aspx.cs:
Code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace Nable_Soft
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
public OleDbConnection con;
public OleDbDataAdapter dAdapter;
public DataSet dSet;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
public string conString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=data.mdb";
public string SQL;
private void InitializeComponent()
{
}
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
con =new OleDbConnection(conString);
SQL = "UPDATE people SET FName = 'asd' , LName = 'wrwerwer'";
OleDbCommand cmd = new OleDbCommand(SQL,con);
con.Open();
cmd.ExecuteNonQuery();
dAdapter = new OleDbDataAdapter();
dAdapter.SelectCommand = new OleDbCommand("select FName,LName from people", con);
dSet=new DataSet();
//refreshes rows in the DataSet
dAdapter.Fill(dSet);
DataGrid1.DataSource = dSet;
DataGrid1.DataMember = "people";
DataGrid1.DataBind();
con.Close();
}
}
}
any help?
thanks
|