'*************************************** ' Notes: ' ' strSQL - SQL Select Statement Used To Open The Table ' objCommandBuilder - Previously Set Using strSQL ' '*************************************** ... ... ... '*************************************** ' Check If Table Has an ID Column '*************************************** If Me.Tables(strTableName).Columns.Contains("ID") Then objAdapter.InsertCommand = New SqlClient.SqlCommand With objAdapter.InsertCommand '*************************************** ' Append Select SQL After INSERT Statement (For Int Identity Retrieval) '*************************************** .CommandType = CommandType.Text .CommandText = objCommandBuilder.GetInsertCommand.CommandText .CommandText &= ";" & strSQL & " WHERE ID = SCOPE_IDENTITY()" .Connection = objConnection End With End If ... ... ...Now if my original SQL Select Statement was more complex then a simple Select Statement, I get the following problem...
'Original Select Statement strSQL = "SELECT * from tblInfo ORDER BY [Year] DESC" 'Modified Insert Statement (When Using the Update Method) strSQL = "INSERT INTO tblInfo(Year, Description, Description2, Address1, Address2, City, State, Zip, Phone, Fax, Contact, CenterID)" & _ "VALUES (@p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10, @p11, @p12);" & _ "SELECT * FROM tblInfo ORDER BY [Year] DESC WHERE ID = SCOPE_IDENTITY()"As you can see, the WHERE Clause ended up after the ORDER BY Clause, which causes an error. I need to find a way (if possibly) to parse an SQL Statement into it's individual clauses, that way I can insert my WHERE Clause into the proper location. If anyone (possible) knows of a SQLPaserClass out there, or maybe something that I am overlooking in the .Net language that can help me, or even any other way of approaching this particular problem in another fasion that I don't know about...I would be greatful.