Help needed with syntax

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
 
M

Marina

It has nothing to do with the syntax of your functions, they're fine.

You are calling those functions - but you are not assigning the result to
the variables you've declared. So they do their job, return the result - but
that result is discarded, since there is no assignment happening. The
compiler can't know which variable you mean to assign to which function
call.
 
E

EricJ

instaid of
SQLColumnNames("Person_ID")
SQLFromClause("Person")
SQLWhereClause("company_ID > 3623")
SQLOrderClause("company_ID")
SQLSelectStatement = "Select" & ColumnNames & FromClause &
WhereClause & OrderClause

try this
SQLSelectStatement = "Select" & SQLColumnNames("Person_ID") &
SQLFromClause("Person") & _
SQLWhereClause("company_ID > 3623") & SQLOrderClause("company_ID")

But i don't have a qlue why you would want to do this using functions? I
think you would get a better functionallity using vars. If you are working
on web pages i would suggest having a look at the session vars (to keep
values for a user as he is posting back pages)

hope it helps

eric
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top