Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Null instead of value

Status
Not open for further replies.

Stegmite

Programmer
Aug 18, 2004
36
US
Dim vNewFunds As Integer
Dim myNewFunds As String = "UPDATE tblChar SET Cash = " & vNewFunds & " WHERE Username = '" & vName & "'"
Dim myNewFundsCommand As New OleDb.OleDbCommand(myNewFunds, OleDbConnection1)

This is my SQL statement to update a value on an Access backend. Whenever I run the ExecuteNonQuery, the cell becomes a null value. Please tell me a better way to approach this.
 
It looks like you've never assigned a value to the vNewFunds variable.

I would try this:

Code:
Dim vNewFunds As Integer[b] = 100[/b]
Dim myNewFunds As String = "UPDATE tblChar SET Cash = " & vNewFunds & " WHERE Username = '" & vName & "'"
Dim myNewFundsCommand As New OleDb.OleDbCommand(myNewFunds, OleDbConnection1)

If that doesn't work, try this:

Code:
Dim myNewFunds As String = "UPDATE tblChar SET [b]Cash = 100[/b] WHERE Username = '" & vName & "'"
Dim myNewFundsCommand As New OleDb.OleDbCommand(myNewFunds, OleDbConnection1)

then try this:

Code:
Dim myNewFunds As String = "UPDATE tblChar SET Cash = [b]" & 100 & "[/b] WHERE Username = '" & vName & "'"
Dim myNewFundsCommand As New OleDb.OleDbCommand(myNewFunds, OleDbConnection1)

Somewhere in there you ought to be able to narrow down the problem.

You may also want to consider using parameters:

Code:
Dim vNewFunds As Integer
Dim myNewFunds As String = _
   "UPDATE tblChar " & _
   "SET Cash = [?Cash] " & _
   "WHERE Username = [?Username]"
Dim myNewFundsCommand As New OleDb.OleDbCommand(myNewFunds, OleDbConnection1)

myNewFundsCommand.Parameters.Add("?Cash", vNewFunds)
myNewFundsCommand.Parameters.Add("?Username", vName)

This will keep Irishmen like O'Brian from screwing up your query.
 
I am setting values, I just didn't put that part in.
Code:
vNewFunds = vFunds - vCost
The column is a Number field
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top