Click here to Skip to main content
15,900,815 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I’m trying to create Web Application using ASP.Net via Visual Studio 2010.
The Database that I use is Access, with connection Method OleDb

When using the query “Update” or “Delete”, the programs shows no errors, but the data in Access does not change.
While for query “Select” and “Insert”, the data is displayed and inserted successfully.

The Following code is the sample query “Delete” that I used..

HTML
Imports System.Data.OleDb

Partial Class frmTEst
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
       
    Dim dbConnection As OleDbConnection
        Dim dbCommand As OleDbCommand
        Dim sqlString As String

        dbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; _
Data Source=" & Server.MapPath("App_Data/dbKAE.mdb"))
        dbConnection.Open()

        sqlString = "DELETE FROM tblPengawasan WHERE no='31'"

        dbCommand = New OleDbCommand(sqlString, dbConnection)
        dbCommand.ExecuteNonQuery()

    End Sub
End Class


Previously I tried a direct query using AccessDataSource, but the result just the same, “Update” and “Delete” can’t be done. But the “Select” and “Insert” can be executed successfully.

Is there any problem with my Access configuration or whether the problem is in the coding itself..?

Thanks..
Posted
Comments
RaisKazi 26-Oct-11 4:44am    
What is a Data-Type of Column-"no"?
Amir Mahfoozi 26-Oct-11 5:11am    
after delete or update , close and reopen the connection. I think it is a refresh problem.

Looks like your statement does not work when you user a where clause (update/Delete) and the possible reason for this could be the data type mismatch.

Your "no" column in the database may be not a text type but a number and when you use WHERE no='31' the query does not get executed (data type mismatch in your where clause) and goes unnoticed because you have not hanled the exceptions.

Check you database and if the column type is number / autonumber try using
WHERE no=31 (without single quote) and it should work
 
Share this answer
 
v3
If you do not get any exception when you execute the code, then the most likely error is that the database does not contain any columns where "no" is equal to "31". Check it, and make sure you are referencing the right database both when you check, and when you run the code.

It is also worth adding some logging to make sure you are executing the code. I would also put a try-catch block around the whole code to make sure that you don't get any exceptions, and to report them if you do.
 
Share this answer
 
Delete
sqlString = "DELETE FROM tblPengawasan WHERE columnname= '" + 31(based on your desired string) + "'"

Update
SqlCommand sqlCmd = new SqlCommand(string.Format("Update [tblPengawasan ] set Column1= '{0}' where columnname='{1}'", Column1.String1, columnname.String2), dbConnection );

For more information please refer to Google ^_^

Happy Coding
 
Share this answer
 
Comments
janwel 26-Oct-11 5:12am    
Im not into C# cause ive focused on vb but hope you catch what I am trying to say
Thanks everyone. I can executed "Update" and "Delete" now..
you are right, the problem is type mismatch in my "no" column, that was autoNumber type.

Thank you too for the suggestion in using try-catch block (usually i not use it heheheh).. i'll use it for my entire coding..

thanks again for helping me..
 
Share this answer
 
SQL
Vote:


Solution 3Accept Solution Reject Solution
Looks like your statement does not work when you user a where clause (update/Delete) and the possible reason for this could be the data type mismatch.

Your "no" column in the database may be not a text type but a number and when you use WHERE no='31' the query does not get executed (data type mismatch in your where clause) and goes unnoticed because you have not hanled the exceptions.

Check you database and if the column type is number / autonumber try using
WHERE no=31 (without single quote) and it should work



from Cheap New Era Hats
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900