Showing posts with label updating. Show all posts
Showing posts with label updating. Show all posts

Saturday, March 24, 2012

Trouble updating

I have a Access database with 2 text fields. I'm reading one field into a text box, changing the value in the textbox and attempting to update the database with the new value. The page loads fine with the correct value in the textbox, but I'm getting a error on the Update statement. Below is the code. Any suggestions?

Sub LoadInventory()
Connect()
Dim strQuery As String = "SELECT Type, Number FROM Inventory WHERE type = 'squares'"

Dim dbComm As New OLEDBCommand(strQuery, objConnection)
Dim reader As OLEDBDataReader = dbComm.ExecuteReader()

reader.Read()
txtAmount.Text = reader.GetString(1)

reader.Close()
Disconnect()
End Sub

Sub btnChange_Click(ByVal Sender As Object, ByVal E As EventArgs)
UpdateInventory()
LoadInventory()
End Sub

Private Sub UpdateInventory()
Dim strSQL As String = "UPDATE Inventory SET Number = " & txtAmount.Text & " WHERE Type = 'squares'"
Connect()
Dim dbComm As New OLEDBCommand(strSQL, objConnection)
dbComm.ExecuteNonQuery()
Disconnect()
End Subinstead of

Dim strSQL As String = "UPDATE Inventory SET Number = " & txtAmount.Text & " WHERE Type = 'squares'"

try this
Dim strSQL As String = "UPDATE Inventory SET Number = " & Convert.ToInt32(txtAmount.Text) & " WHERE Type = 'squares'"

Jeff
Jeff,

Thanks for your reply. That however didn't work. Could it be the way I have my access database setup?

Jeremy
Jeff,

Does it work when you try putting in a static value for txtAmount.Text such as this:

"UPDATE Inventory SET Number =1 WHERE Type='squares'"

If it does work like that, then try doing this:


Try
Dim dbComm As New OLEDBCommand(strSQL, objConnection)
dbComm.ExecuteNonQuery()
Catch dbException As Exception
Response.Write(dbException.ToString())
End Try

Tell us what the exception is. Besides, it is always good practice anyway to put database queries inside a try statement - there are just way too many things that could go wrong to not catch those errors.

Aaron

Trouble updating version to 1.1

Having trouble getting the my.net framework to version 1.1 I downloaded it, ran the setup.exe, and restarted. I open up my visual stud .net and it says 1.0. Please helpVS.NET 2002 will only work with 1.0 of the framework, and VS.NET 2003 will only work with the 1.1 framework. Does that give you an idea of whats wrong.
I thought you were able to update the framework. Anyway, I guess that would be the problem then. So, there is no way I can share projects that are created in vs.net 2003 using vs.net 2002. For instance, "arParams[0] = new SqlParameter("@.RegionId", ddlRegion.SelectedValue);" does not work in 2002, but does in 2003... .selectedValue is an issue.
You can install different frameworks, but VS.NET 2002 and VS.NET 2003 cannot switch between the different frameworks.

Your assumption is correct, there is no way of doing what you wish if you want to code against the 1.0 framework (using VS.NET 2002).
so i have to buy vs.net 2003 to view these projects?
Well, yes and no. To get the full IDE experience, I'd say yes. But, you can do command line compilations, if you wish.