Two SQL strings to get two DataTables in one DataS

qubed

New Member
I'm trying to pass two SQL strings separated by a semicolon to the database to get two DataTables back in one DataSet, but it throws an error when using the DataAdapter's Fill method saying "Characters found after end of SQL statement." (I modified code I found at http://www.dotnetjunkies.com/tutorials.aspx?tutorialid=135)<BR><BR>Here's the code I'm using:<BR><BR>strConn = Session("ConnectString").ToString<BR><BR>strSQL = String.Format("SELECT Sum(tblPlayerGame.Runs) AS SumOfRuns" & _<BR> " FROM tblPlayer INNER JOIN tblPlayerGame ON tblPlayer.PlayerID = tblPlayerGame.PlayerID" & _<BR> " WHERE tblPlayerGame.GameID={0} AND tblPlayer.TeamID={1}", CInt(txtGameID.Text), CInt(txtVisitorTeamID.Text))<BR> strSQL = strSQL & "; " & String.Format("SELECT Sum(tblPlayerGame.Runs) AS SumOfRuns" & _<BR> " FROM tblPlayer INNER JOIN tblPlayerGame ON tblPlayer.PlayerID = tblPlayerGame.PlayerID" & _<BR> " WHERE tblPlayerGame.GameID={0} AND tblPlayer.TeamID={1}", CInt(GameID.Text), CInt(txtHomeTeamID.Text))<BR><BR> ds = DataHandler.GetDataSet(strSQL, strConn)<BR><BR><BR>And here's my DataHandler's GetDataSet method:<BR><BR> Public Shared Function GetDataSet( _<BR> ByVal SQLString As String, ByVal ConnectionString As String) As DataSet<BR><BR> Dim da As OleDbDataAdapter<BR> Dim ds As DataSet<BR><BR> Try<BR> ' Create a new DataAdapter<BR> da = New OleDbDataAdapter(SQLString, ConnectionString)<BR><BR> ' Fill the DataSet from DataAdapter<BR> ds = New DataSet()<BR> da.Fill(ds)<BR><BR> Catch<BR> Throw<BR> End Try<BR><BR> Return ds<BR><BR> End Function*****************************<BR>strSQL = String.Format("SELECT Sum(tblPlayerGame.Runs) AS SumOfRuns" & _ <BR>" FROM tblPlayer INNER JOIN tblPlayerGame ON tblPlayer.PlayerID = tblPlayerGame.PlayerID" & _ <BR>" WHERE tblPlayerGame.GameID={0} AND tblPlayer.TeamID={1}", CInt(txtGameID.Text), CInt(txtVisitorTeamID.Text)) <BR>******************************<BR><BR>this is the first part of your strSQL string. It is far away from being a syntactically correct string.maybe you wanted to say this<BR><BR><BR>strSQL = String.Format("SELECT Sum(tblPlayerGame.Runs) AS SumOfRuns" & _ <BR>" FROM tblPlayer INNER JOIN tblPlayerGame ON tblPlayer.PlayerID = tblPlayerGame.PlayerID" & _ <BR>" WHERE tblPlayerGame.GameID={0} AND tblPlayer.TeamID={1}, " & CInt(txtGameID.Text) & ", " & CInt(txtVisitorTeamID.Text)) <BR><BR><BR>but that doesn't make any sql sense... you gotto explain some more about what you are trying to achieve
 
Back
Top