Results 1 to 7 of 7

Thread: [RESOLVED] SQL Check!.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Resolved [RESOLVED] SQL Check!.

    This is part of my other thread from Updating a table with records in an XML dataset.
    Here my problem is, i want to INSERT records with a SELECTION Criteria of all users but not the user logged in.
    In the code below, i get an SQL Exception. "missing Semicolon at the end of the SQL Statement".
    When i put the semicolon before the SELECT statement, it tells me
    "Character Found After the End Of the SQl statement"
    Is this the correct SQL statement for this?
    VB Code:
    1. Private Sub update_tblPopulatedPlaces_fromXML()
    2.         Dim dsXMLImport As New DataSet
    3.         myConn = New OleDbConnection(strAccessConn)
    4.         Dim strSQL As String = "INSERT INTO tblPopulatedPlaces(AdminBdry1_ID,AdminBdry2_ID,AdminBdry3_ID,AdminBdry4_ID,PPname,uid_Created,date_Created,uid_Modified,date_Modified)" & _
    5.         " VALUES(@AdminBdry1_ID,@AdminBdry2_ID,@AdminBdry3_ID,@AdminBdry4_ID,@PPname,@uid_Created,@date_Created,@uid_Modified,@date_Modified)" & _
    6.         " SELECT * FROM tblPopulatedPlaces WHERE([uid_Created] <> '" & user.userName.ToString & "')"
    7.         Dim da As New OleDbDataAdapter()
    8.         da.AcceptChangesDuringFill = False
    9.         da.InsertCommand = New OleDbCommand(strSQL, myConn)
    10.         Try
    11.             myConn.Open()
    12.             dsXMLImport.ReadXml(Me.tbFilePath.Text)
    13.             With da.InsertCommand.Parameters
    14.                 For i As Integer = 0 To dsXMLImport.Tables(1).Rows.Count - 1
    15.                     drPublic = dsXMLImport.Tables(1).Rows(i)
    16.                     .AddWithValue("@AdminBdry1_ID", drPublic(1))
    17.                     .AddWithValue("@AdminBdry2_ID", drPublic(2))
    18.                     .AddWithValue("@AdminBdry3_ID", drPublic(3))
    19.                     .AddWithValue("@AdminBdry4_ID", drPublic(4))
    20.                     .AddWithValue("@PPname", drPublic(5))
    21.                     .AddWithValue("@uid_Created", drPublic(6))
    22.                     .AddWithValue("@date_Created", drPublic(7))
    23.                     .AddWithValue("@uid_Modified", drPublic(8))
    24.                     .AddWithValue("@date_Modified", drPublic(9))
    25.                 Next i
    26.             End With
    27.             da.Update(dsXMLImport, dsXMLImport.Tables(1).TableName)
    28.         Catch exSQL As OleDbException
    29.             ShowErrorBoxOK("update_tblPopulatedPlaces_fromXML():", exSQL.Message, My.Resources.myStrings.capSQLError)
    30.         Catch ex As Exception
    31.             ShowErrorBoxOK("update_tblPopulatedPlaces_fromXML():", ex.Message, My.Resources.myStrings.capGeneralError)
    32.         Finally
    33.             myConn.Close()
    34.             myConn.Dispose()
    35.             da.Dispose()
    36.         End Try
    37.     End Sub
    Last edited by maps; Nov 9th, 2006 at 05:11 AM.

  2. #2
    Hyperactive Member josep's Avatar
    Join Date
    Sep 2006
    Location
    Barcelona
    Posts
    409

    Re: SQL Check!.

    Hi,

    you must put the semicolon after the select statment (in red)

    VB Code:
    1. Dim strSQL As String = "INSERT INTO tblPopulatedPlaces(AdminBdry1_ID,AdminBdry2_ID,AdminBdry3_ID,AdminBdry4_ID,PPname,uid_Created,date_C  reated,uid_Modified,date_Modified)" & _
    2.         " VALUES(@AdminBdry1_ID,@AdminBdry2_ID,@AdminBdry3_ID,@AdminBdry4_ID,@PPname,@uid_Created,@date_Create  d,@uid_Modified,@date_Modified)" & _
    3.         " SELECT * FROM tblPopulatedPlaces WHERE([uid_Created] <> '" & user.userName.ToString & "')[COLOR=Red];[/COLOR]"

    Hope this helps
    Useful links:DB connection strings ADO.NET VB.NET Tutorials

    • Don't forget to close the thread if solved
    • If this post helps you rate it

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: SQL Check!.

    I get the same Error message.
    VB Code:
    1. Dim strSQL As String = "INSERT INTO tblPopulatedPlaces(AdminBdry1_ID,AdminBdry2_ID,AdminBdry3_ID,AdminBdry4_ID,PPname,uid_Created,date_Created,uid_Modified,date_Modified)" & _
    2.         " VALUES(@AdminBdry1_ID,@AdminBdry2_ID,@AdminBdry3_ID,@AdminBdry4_ID,@PPname,@uid_Created,@date_Created,@uid_Modified,@date_Modified);" & _
    3.         " SELECT * FROM tblPopulatedPlaces WHERE([uid_Created] <> '" & user.userName.ToString & "');"

  4. #4
    Hyperactive Member josep's Avatar
    Join Date
    Sep 2006
    Location
    Barcelona
    Posts
    409

    Re: SQL Check!.

    Did you tried without the semicolon after the insert statment, a I typed or with it as you typed, or both?
    Useful links:DB connection strings ADO.NET VB.NET Tutorials

    • Don't forget to close the thread if solved
    • If this post helps you rate it

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: SQL Check!.

    Yes i did.
    when i have this below, i get the exception
    "Missing Semiclon at the end of SQL statement"
    VB Code:
    1. Dim strSQL As String = "INSERT INTO tblPopulatedPlaces(AdminBdry1_ID,AdminBdry2_ID,AdminBdry3_ID,AdminBdry4_ID,PPname,uid_Created,date_Created,uid_Modified,date_Modified)" & _
    2.         " VALUES(@AdminBdry1_ID,@AdminBdry2_ID,@AdminBdry3_ID,@AdminBdry4_ID,@PPname,@uid_Created,@date_Created,@uid_Modified,@date_Modified)" & _
    3.         " SELECT * FROM tblPopulatedPlaces WHERE([uid_Created] <> '" & user.userName.ToString & "');"

    When i dont have any semicolon anywhere, i get the same error!

    When i have two semicolons, i get the Exception
    "Characters Found After the End Of the SQl statement"

  6. #6
    Hyperactive Member josep's Avatar
    Join Date
    Sep 2006
    Location
    Barcelona
    Posts
    409

    Re: SQL Check!.

    You can try to add a carriage return between both queries,


    VB Code:
    1. Dim strSQL As String = "INSERT INTO tblPopulatedPlaces(AdminBdry1_ID,AdminBdry2_ID,AdminBdry3_ID,AdminBdry4_ID,PPname,uid_Created,date_C  reated,uid_Modified,date_Modified)" & _
    2.         " VALUES(@AdminBdry1_ID,@AdminBdry2_ID,@AdminBdry3_ID,@AdminBdry4_ID,@PPname,@uid_Created,@date_Create  d,@uid_Modified,@date_Modified);" & cbcrlf & _
    3.         "SELECT * FROM tblPopulatedPlaces WHERE([uid_Created] <> '" & user.userName.ToString & "');"

    if it did not work you can launch it separately; first the insert statment probably using the method executenonquery and after that launch the select
    Useful links:DB connection strings ADO.NET VB.NET Tutorials

    • Don't forget to close the thread if solved
    • If this post helps you rate it

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: SQL Check!.

    It has Jammed. Let me try launching them separately.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width