A
Aaron
Can someone tell my why my functions are returning "nothing"?
In the SQLStatement Sub, ColumnNames & FromClause & WhereClause &
OrderClause all come up as "nothing". I can't figure out why my
functions are not working. When I step through the code, the parameter
is passed, but as soon as it executes the return line, the strings are
set to "nothing.
Any ideas?
Thanks,
Aaron
Public Class WebForm2
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
SQLStatement()
End Sub
Function SQLConnect(ByVal ServerName As String, ByVal UserName As
String, ByVal Password As String, ByVal Database As String) As
SqlClient.SqlConnection
Dim sqlcon As New SqlClient.SqlConnection() ' Dim new SQL
connection object
sqlcon.ConnectionString = "Server=" & ServerName & ";User ID=" &
UserName & ";password=" & Password & ";Database=" & Database ' Connection
string
sqlcon.Open() ' Open a connection to the DB
Return sqlcon
End Function
Function SQLColumnNames(ByVal Columns As String) As String
Dim ColumnNames As String
ColumnNames = Columns
Return ColumnNames
End Function
Function SQLFromClause(ByVal TableName As String) As String
Dim FromClause As String
FromClause = " From " & TableName
Return FromClause
End Function
Function SQLWhereClause(ByVal Criteria As String) As String
Dim WhereClause As String
WhereClause = " Where " & Criteria
Return WhereClause
End Function
Function SQLOrderClause(ByVal OrderColumn As String) As String
Dim OrderClause As String
OrderClause = " Order by " & OrderColumn
Return OrderClause
End Function
Sub SQLStatement()
Dim SqlCon As SqlClient.SqlConnection
Dim DA As SqlClient.SqlDataAdapter
Dim SqlCmd As SqlClient.SqlCommand
Dim SQLSelectStatement As String
Dim ColumnNames As String
Dim FromClause As String
Dim WhereClause As String
Dim OrderClause As String
Dim DS As DataSet
SqlCon = SQLConnect("Boca2", "USER", "PASSWORD", "pursuittest")
SQLColumnNames("Person_ID")
SQLFromClause("Person")
SQLWhereClause("company_ID > 3623")
SQLOrderClause("company_ID")
SQLSelectStatement = "Select" & ColumnNames & FromClause &
WhereClause & OrderClause
SqlCmd.CommandText = SQLSelectStatement
DA.SelectCommand = SqlCmd
DA.Fill(DS, "test")
SqlCon.Close()
End Sub
End Class
In the SQLStatement Sub, ColumnNames & FromClause & WhereClause &
OrderClause all come up as "nothing". I can't figure out why my
functions are not working. When I step through the code, the parameter
is passed, but as soon as it executes the return line, the strings are
set to "nothing.
Any ideas?
Thanks,
Aaron
Public Class WebForm2
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
SQLStatement()
End Sub
Function SQLConnect(ByVal ServerName As String, ByVal UserName As
String, ByVal Password As String, ByVal Database As String) As
SqlClient.SqlConnection
Dim sqlcon As New SqlClient.SqlConnection() ' Dim new SQL
connection object
sqlcon.ConnectionString = "Server=" & ServerName & ";User ID=" &
UserName & ";password=" & Password & ";Database=" & Database ' Connection
string
sqlcon.Open() ' Open a connection to the DB
Return sqlcon
End Function
Function SQLColumnNames(ByVal Columns As String) As String
Dim ColumnNames As String
ColumnNames = Columns
Return ColumnNames
End Function
Function SQLFromClause(ByVal TableName As String) As String
Dim FromClause As String
FromClause = " From " & TableName
Return FromClause
End Function
Function SQLWhereClause(ByVal Criteria As String) As String
Dim WhereClause As String
WhereClause = " Where " & Criteria
Return WhereClause
End Function
Function SQLOrderClause(ByVal OrderColumn As String) As String
Dim OrderClause As String
OrderClause = " Order by " & OrderColumn
Return OrderClause
End Function
Sub SQLStatement()
Dim SqlCon As SqlClient.SqlConnection
Dim DA As SqlClient.SqlDataAdapter
Dim SqlCmd As SqlClient.SqlCommand
Dim SQLSelectStatement As String
Dim ColumnNames As String
Dim FromClause As String
Dim WhereClause As String
Dim OrderClause As String
Dim DS As DataSet
SqlCon = SQLConnect("Boca2", "USER", "PASSWORD", "pursuittest")
SQLColumnNames("Person_ID")
SQLFromClause("Person")
SQLWhereClause("company_ID > 3623")
SQLOrderClause("company_ID")
SQLSelectStatement = "Select" & ColumnNames & FromClause &
WhereClause & OrderClause
SqlCmd.CommandText = SQLSelectStatement
DA.SelectCommand = SqlCmd
DA.Fill(DS, "test")
SqlCon.Close()
End Sub
End Class