revised but still not inserting (error near keyword "where")

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2008
Posts: 34
Reputation: ricksvoid is an unknown quantity at this point 
Solved Threads: 0
ricksvoid ricksvoid is offline Offline
Light Poster

revised but still not inserting (error near keyword "where")

 
0
  #1
Oct 28th, 2009
I just keep getting the same error. can not insert record. Problem near keyword "where".

  1. Imports System.Security
  2. Imports System.Data.SqlClient
  3. Imports System.Web.Configuration
  4. Imports System.Data
  5.  
  6.  
  7. Partial Class admin
  8. Inherits System.Web.UI.Page
  9. Public connectPath As String = ConfigurationSettings.AppSettings("Maya")
  10.  
  11.  
  12. Protected Sub fillDropList(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  13. If Not Page.IsPostBack Then
  14. DropList1.DataSource = Membership.GetAllUsers()
  15. DropList1.DataBind()
  16. End If
  17. End Sub
  18.  
  19. Protected Sub DropList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropList1.SelectedIndexChanged
  20. Dim theUser2 As Integer = names.SelectedDataKey.Value
  21. Dim con As New SqlConnection
  22. con.ConnectionString = connectPath
  23.  
  24. 'the customerID of the selected gridview row
  25.  
  26.  
  27. Dim setRep As New SqlCommand
  28. setRep.Connection = con
  29. setRep.CommandText = "INSERT INTO dbo.customers(rep)VALUES(@dropList1)WHERE customerID = @ID"
  30. setRep.Parameters.AddWithValue("@dropList1", DropList1.SelectedItem.ToString())
  31. setRep.Parameters.AddWithValue("@ID", gridView1.SelectedDataKey.Value)
  32.  
  33. Dim added As Integer = 0
  34. Try
  35. con.Open()
  36.  
  37. added = setRep.ExecuteNonQuery()
  38.  
  39. results.Text = added.ToString() & "record has been added!"
  40.  
  41.  
  42.  
  43. Catch Err As Exception
  44. results.Text = "Error inserting record. "
  45. results.Text &= Err.Message
  46. Finally
  47. con.Close()
  48. End Try
  49.  
  50.  
  51. End Sub
  52.  
  53.  
  54. End Class
  55.  
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 34
Reputation: ricksvoid is an unknown quantity at this point 
Solved Threads: 0
ricksvoid ricksvoid is offline Offline
Light Poster

A simple SQL problem. Can anyone figure it out?

 
-1
  #2
Oct 28th, 2009
This is probably so simple but i just cant seen to figure it out. Im trying to insert the dropList1.selected.value into the column named "rep" in the dbo.customers table where customerID= the customer id of my gridview.

evidently there is a problem near key word "where" in my sql command text. Even when i try hard coding values such as
  1. INSERT INTO dbo.customers(rep) VALUES(some text) WHERE customerID = 48

I still get an error. what am i doing wrong?????
thanks in advance
Rick Pace

  1.  
  2. Dim setRep As New SqlCommand
  3. setRep.Connection = con
  4. setRep.CommandText = "INSERT INTO dbo.customers(rep)VALUES(@dropList1)WHERE customerID =@ID"
  5. setRep.Parameters.AddWithValue("@dropList1", DropList1.SelectedValue.ToString())
  6. setRep.Parameters.AddWithValue("@ID", gridView1.SelectedDataKey.Value)
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 220
Reputation: mail2saion is an unknown quantity at this point 
Solved Threads: 33
mail2saion's Avatar
mail2saion mail2saion is offline Offline
Posting Whiz in Training
 
0
  #3
Oct 29th, 2009
Which error you get?? What is your CustomerID field? Does it autogenerated? If not then check that you may miss must have field values. Please post your error.
MARK AS SOLVED if its help you.

REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,230
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 574
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast
 
0
  #4
Oct 29th, 2009
That is invalid SQL and normally I would post the correct SQL but I have no clue what you're trying to do.

Valid SQL is simply:
  1. INSERT INTO dbo.customers (col1, col2) VALUES (@val1, @val2)

Are you trying to UPDATE the table instead of INSERT maybe?

  1. UPDATE dbo.Customers
  2. SET
  3. col1 = @val1,
  4. col2 = @val2
  5. WHERE id = @id
Last edited by sknake; Oct 29th, 2009 at 3:12 am.
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 220
Reputation: mail2saion is an unknown quantity at this point 
Solved Threads: 33
mail2saion's Avatar
mail2saion mail2saion is offline Offline
Posting Whiz in Training
 
0
  #5
Oct 29th, 2009
OHHHHH Yes please read basic concept on writing SQL. In Insert statement why where clause??
MARK AS SOLVED if its help you.

REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC