473,414 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

access database not updating

When I try to update my access database, nothing get updated. Here is my
code:

<%@ Page Language="VB" Debug="true" %>
<script runat="server">

' Insert page code here
'

Function UpdateCustomer(ByVal ProjectID As String, ByVal ProjectName
As String) As Integer
Dim connectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data
Source=D:\Websites\Demo\GI2005.mdb"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString )

Dim queryString As String = "UPDATE [TProject] SET
[ProjectName]=@ProjectName WHERE ([TProject].[ProjectID] = @Proj"& _
"ekID)"

Dim dbCommand As System.Data.IDbCommand = New
System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_ProjectID As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_ProjectID.ParameterName = "@ProjectID"
dbParam_ProjectID.Value = ProjectID
dbParam_ProjectID.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_ProjectID)
Dim dbParam_ProjectName As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_ProjectName.ParameterName = "@ProjectName"
dbParam_ProjectName.Value = ProjectName
dbParam_ProjectName.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_ProjectName)

Dim rowsAffected As Integer = 0
dbConnection.Open
Try
rowsAffected = dbCommand.ExecuteNonQuery
Finally
dbConnection.Close
End Try

Return rowsAffected
End Function

Function GetTProject() As System.Data.IDataReader
Dim connectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data
Source=D:\Websites\Demo\GI2005.mdb"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString )

Dim queryString As String = "SELECT [TProject].* FROM
[TProject]"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

dbConnection.Open
Dim dataReader As System.Data.IDataReader =
dbCommand.ExecuteReader(System.Data.CommandBehavio r.CloseConnection)

Return dataReader
End Function

Sub dgCustomers_Edit(sender as Object, e as
DataGridCommandEventArgs)
dgCustomers.EditItemIndex = e.Item.ItemIndex

dgCustomers.DataSource = GetTProject()
dgCustomers.DataBind()
End Sub
Sub dgCustomers_Update(sender as Object, e as
DataGridCommandEventArgs)

Dim ProjectID as String = e.Item.Cells(1).Text

Dim ProjectName as TextBox = e.Item.Cells(2).Controls(0)

UpdateCustomer(ProjectID, ProjectName.Text)

dgCustomers.EditItemIndex = -1

dgCustomers.DataSource = GetTProject()
dgCustomers.DataBind()
End Sub
Sub dgCustomers_Cancel(sender as Object, e as
DataGridCommandEventArgs)
dgCustomers.EditItemIndex = -1

dgCustomers.DataSource = GetTProject()
dgCustomers.DataBind()
End Sub
Sub Page_Load(sender as Object, e as EventArgs)
If Not Page.IsPostBack then
dgCustomers.DataSource = GetTProject()
dgCustomers.DataBind()
End If
End Sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
</p>
<p>
<asp:DataGrid id="dgCustomers" runat="server"
AutoGenerateColumns="False" OnCancelCommand="dgCustomers_Cancel"
OnUpdateCommand="dgCustomers_Update" OnEditCommand="dgCustomers_Edit">
<Columns>
<asp:EditCommandColumn ButtonType="LinkButton"
UpdateText="Update" CancelText="Cancel"
EditText="Edit"></asp:EditCommandColumn>
<asp:BoundColumn DataField="ProjectID" ReadOnly="True"
HeaderText="ProjectID"></asp:BoundColumn>
<asp:BoundColumn DataField="ProjectName"
HeaderText="ProjectName"></asp:BoundColumn>
</Columns>
</asp:DataGrid>
<!-- Insert content here -->
</p>
</form>
</body>
</html>
Nov 19 '05 #1
1 1430
Hi Gert,

The probable reason is before executing UpdateCustomer
you run dgCustomers.DataSource = GetTProject(), e.g. in Page_Load. Hence data
changed by user, e.g. ProjectName, is overwritten by data source. The correct
approach is to only bind datagrid with data source when
it's not postback:

If Not IsPostback Then
dgCustomers.DataSource = GetTProject()
dgCustomers.DataBind()
End If

HTH
Elton Wang
el********@hotmail.com

"Gert Albertse" wrote:
When I try to update my access database, nothing get updated. Here is my
code:

<%@ Page Language="VB" Debug="true" %>
<script runat="server">

' Insert page code here
'

Function UpdateCustomer(ByVal ProjectID As String, ByVal ProjectName
As String) As Integer
Dim connectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data
Source=D:\Websites\Demo\GI2005.mdb"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString )

Dim queryString As String = "UPDATE [TProject] SET
[ProjectName]=@ProjectName WHERE ([TProject].[ProjectID] = @Proj"& _
"ekID)"

Dim dbCommand As System.Data.IDbCommand = New
System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_ProjectID As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_ProjectID.ParameterName = "@ProjectID"
dbParam_ProjectID.Value = ProjectID
dbParam_ProjectID.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_ProjectID)
Dim dbParam_ProjectName As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_ProjectName.ParameterName = "@ProjectName"
dbParam_ProjectName.Value = ProjectName
dbParam_ProjectName.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_ProjectName)

Dim rowsAffected As Integer = 0
dbConnection.Open
Try
rowsAffected = dbCommand.ExecuteNonQuery
Finally
dbConnection.Close
End Try

Return rowsAffected
End Function

Function GetTProject() As System.Data.IDataReader
Dim connectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data
Source=D:\Websites\Demo\GI2005.mdb"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString )

Dim queryString As String = "SELECT [TProject].* FROM
[TProject]"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

dbConnection.Open
Dim dataReader As System.Data.IDataReader =
dbCommand.ExecuteReader(System.Data.CommandBehavio r.CloseConnection)

Return dataReader
End Function

Sub dgCustomers_Edit(sender as Object, e as
DataGridCommandEventArgs)
dgCustomers.EditItemIndex = e.Item.ItemIndex

dgCustomers.DataSource = GetTProject()
dgCustomers.DataBind()
End Sub
Sub dgCustomers_Update(sender as Object, e as
DataGridCommandEventArgs)

Dim ProjectID as String = e.Item.Cells(1).Text

Dim ProjectName as TextBox = e.Item.Cells(2).Controls(0)

UpdateCustomer(ProjectID, ProjectName.Text)

dgCustomers.EditItemIndex = -1

dgCustomers.DataSource = GetTProject()
dgCustomers.DataBind()
End Sub
Sub dgCustomers_Cancel(sender as Object, e as
DataGridCommandEventArgs)
dgCustomers.EditItemIndex = -1

dgCustomers.DataSource = GetTProject()
dgCustomers.DataBind()
End Sub
Sub Page_Load(sender as Object, e as EventArgs)
If Not Page.IsPostBack then
dgCustomers.DataSource = GetTProject()
dgCustomers.DataBind()
End If
End Sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
</p>
<p>
<asp:DataGrid id="dgCustomers" runat="server"
AutoGenerateColumns="False" OnCancelCommand="dgCustomers_Cancel"
OnUpdateCommand="dgCustomers_Update" OnEditCommand="dgCustomers_Edit">
<Columns>
<asp:EditCommandColumn ButtonType="LinkButton"
UpdateText="Update" CancelText="Cancel"
EditText="Edit"></asp:EditCommandColumn>
<asp:BoundColumn DataField="ProjectID" ReadOnly="True"
HeaderText="ProjectID"></asp:BoundColumn>
<asp:BoundColumn DataField="ProjectName"
HeaderText="ProjectName"></asp:BoundColumn>
</Columns>
</asp:DataGrid>
<!-- Insert content here -->
</p>
</form>
</body>
</html>

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Lee Rouse | last post by:
Hello all, This is going to be a rather lengthy "question". I have an Access 2k database, separated front end/back end. Front end copies are on about 30 workstations and used frequently during...
0
by: htmlgeek | last post by:
I'm adding and updating records in an Access .mdb via WWW .asp page. Authored in Dreamweaver 2004 MX. Help is welcome on this one. I have a great set of pages that work fine, but it seems that...
49
by: Yannick Turgeon | last post by:
Hello, We are in the process of examining our current main application. We have to do some major changes and, in the process, are questionning/validating the use of MS Access as front-end. The...
1
by: gaosul | last post by:
I am non-programming scientist and I am using a Program called Easyarticles from Synaptosoft Inc., which is based the database program Access. Unfortunately, the owner of this company has...
22
by: Deano | last post by:
Hi, I have a finished Microsoft Access app that we are distributing using an Access runtime. This works fine (mostly) but I'm sold on the advantages of dot.NET and upgrading to vb.NET seems...
3
by: Jess | last post by:
I have an access database that used to be on 1 box and now is on another. There's asp pages calling it. The gals that use it said they used to be able to get into the access database at anytime...
13
by: royaltiger | last post by:
I am trying to copy the inventory database in Building Access Applications by John L Viescas but when i try to run the database i get an error in the orders form when i click on the allocate...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
11
by: bbasberg | last post by:
Hello, I have been struggling with this problem for DAYS and have googled my heart out as well as reading any books I could get my hands on but I cannot find any specific references to my problem....
2
by: anthony | last post by:
I have an old database which started out life in the Access 2 days! It's full of lots of stuff which I'm not convinced is relevant any longer. Would a good way forward be to create a new, blank...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.