944,028 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 641
  • ASP.NET RSS
Oct 28th, 2009
0

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

Expand Post »
I just keep getting the same error. can not insert record. Problem near keyword "where".

ASP.NET Syntax (Toggle Plain Text)
  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.  
Similar Threads
Reputation Points: 9
Solved Threads: 0
Light Poster
ricksvoid is offline Offline
39 posts
since May 2008
Oct 28th, 2009
-1

A simple SQL problem. Can anyone figure it out?

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
ASP.NET Syntax (Toggle Plain Text)
  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

ASP.NET Syntax (Toggle Plain Text)
  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)
Reputation Points: 9
Solved Threads: 0
Light Poster
ricksvoid is offline Offline
39 posts
since May 2008
Oct 29th, 2009
0
Re: revised but still not inserting (error near keyword "where")
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.
Reputation Points: 26
Solved Threads: 44
Posting Whiz in Training
mail2saion is offline Offline
247 posts
since Apr 2009
Oct 29th, 2009
0
Re: revised but still not inserting (error near keyword "where")
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:
sql Syntax (Toggle Plain Text)
  1. INSERT INTO dbo.customers (col1, col2) VALUES (@val1, @val2)

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

sql Syntax (Toggle Plain Text)
  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.
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Oct 29th, 2009
0
Re: revised but still not inserting (error near keyword "where")
OHHHHH Yes please read basic concept on writing SQL. In Insert statement why where clause??
Reputation Points: 26
Solved Threads: 44
Posting Whiz in Training
mail2saion is offline Offline
247 posts
since Apr 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: how to get the header name for the datatable in C#
Next Thread in ASP.NET Forum Timeline: Pop up window on condition in asp.net 2.0





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC