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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update command, what am I missing?

Status
Not open for further replies.

sthmpsn1

MIS
Sep 26, 2001
456
US
I have the following code which isn't updating. Does anyone see an error in it?

Dim dbconn1 As SqlConnection = New SqlConnection("code here")
strInsert = "update goals Set goal1=@goal1, goal2=@goal2, goal3=@goal3, goal4=@goal4, goal5=@goal5, goal6=@goal6, goal7=@goal7, goal8=@goal8, goal9=@goal9, goal10=@goal10 where loginID ='" & loggin.Text & "' And year='" & theyears.Text & "'"
cmdInsert = New SqlCommand(strInsert, dbconn1)
cmdInsert.Parameters.Add("@goal1", goal1.Text)
cmdInsert.Parameters.Add("@goal2", goal2.Text)
cmdInsert.Parameters.Add("@goal3", goal3.Text)
cmdInsert.Parameters.Add("@goal4", goal4.Text)
cmdInsert.Parameters.Add("@goal5", goal5.Text)
cmdInsert.Parameters.Add("@goal6", goal6.Text)
cmdInsert.Parameters.Add("@goal7", goal7.Text)
cmdInsert.Parameters.Add("@goal8", goal8.Text)
cmdInsert.Parameters.Add("@goal9", goal9.Text)
cmdInsert.Parameters.Add("@goal10", goal10.Text)

dbconn1.Open()
cmdInsert.ExecuteNonQuery()
dbconn1.Close()
 
The proper sql syntax for an update is

Update

(column1, column2, column3, column4)
Values
(value1, value2, value3, value4)

Try changing your statement to that, should do the trick

D'Arcy
 
I thought that was how you did insert statements, not update?????
 
Er...uh...THATS RIGHT. Good, I was just...um...testing you...

;)

k...now that I've totally shot any hope you had in me...

- are you sure that your ID and Year criteria are actually matching anything (if not, it won't update)
i.e. If it can't find a matching ID AND a matching Year

- Could be a different way to add paramters, but my code looks like this:
cmdObject.Parameters.Add("@blah", sqldbtype.int).Value = Somevalue

Are you sure that your parameters are being passed in correctly?

- Are you getting any error messages, or is it just not doing it? If you aren't getting any error messages, take a scenario that you're trying to do (i.e. all the values you'd normally pass in as parameters), go to your query analyzer, and try running it against your sql server. If it runs, then there's something with your code. If it doesn't, then you know its a criteria/data/sql server issue.

D'Arcy
 
I just figured it out. On my page load when I added an if statement saying If not ispostback Then it works. Any reason why that would be the case?
 
Depends how your page is working:

Do you mean that on first load it does update now, or if you re-post the page it updates?

When is it SUPPOSED to update (in the page load, or in some button code)

D
 
when you click a button it should update. Not on loads
 
You might have something in your page load code that over-rides the button click event maybe?

When a page is post back, the page_load sub always fires, so by saying the not ispostback thing, any code in your page load that normally fires won't.

So it could be something in there.

D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top