473,839 Members | 1,318 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing variable to SQL string is not working.

Hi folks,

The problem I have is that a query string works if hard-coded but
if I pass a variable to it, it does not work as shown here.

This works:
querystring="SE LECT * FROM USERS WHERE CNAME = 'MICROSOFT'"

This does not work:
Dim var as string
var = "Microsoft"
querystring="SE LECT * FROM USERS WHERE CNAME = " & 'var'"

I have 2 DropDownList controls.

The first control is populated with a dataset of company names.

The second control is populated with a dataset of contact names for
the company that was selected in the first control.

The first control has an OnSelectedIndex Changed event handler.

The first control has a datasource set equal to a function named
GetCompanyNames .

The second control has a datasource set equal to a function named
GetContactNames .

In the OnSelectedIndex Changed event handler, I call the GetContactNames
function to
populate the second control with Contact Names that are associated with the
Company
Name selected in the first control.

All is working well, but the Contact Names in the second control do not
change as
different companies are selected in the first control.

What follows is a pseudo code description of my code:

' THESE ARE CALLED AS GLOBAL VARIABLES AT TOP OF THE PAGE
Dim coName as string
Dim dsCompanyNames as DataSet = New DataSet ( )
Dim dsContacts as DataSet = New DataSet ()

' THIS IS MY OnSelectedIndex Changed EVENT HANDLER
Sub ddlTo_SelectedI ndexChanged(sen der As Object, e As EventArgs)
Dim list As DropDownList = CType(sender, DropDownList)
coName=list.Sel ectedItem.Text
GetContactsFrom CompanyForThisP roject ()
End Sub

' THIS IS MY GETCOMPANYNAMES FUNCTION
Function GetCompanyNames ForThisProject( ) as DataSet
dsCompanyNames. Clear()
Dim strConnString As String = "JET OLEDB PROVIDER AND MDB FILE"
Dim queryString As String = "SELECT COMPANYNAMES FROM USERS WHERE
PROJECT = @PROJECT"

Dim dataAdapter As New OleDbDataAdapte r (querystring, strConnString)

dataAdapter.Fil l(dsCompanyName s, "users")

Return dsCompanyNames
End Function

' THIS IS MY GETCONTACTNAMES FUNCTION
Function GetContactsFrom CompanyForThisP roject () As DataSet
dsContacts.Clea r()
Dim strConnString As String = "JET OLEDB PROVIDER AND PATH TO MDB FILE"
Response.Write( "coName = " & coName)

Dim queryString As String

queryString = "SELECT [users].[name] FROM [users] WHERE
(([users].[cname] = '" & coName & "')" & " AND ([users].[project] = '" &
Session("projec t") & "'))"

' queryString = "SELECT [users].[name] FROM [users] WHERE
(([users]. [cname] = 'FDM') AND ([users].[project] = '" &
Session("projec t") & "'))"

Dim dataAdapter As New OleDbDataAdapte r (querystring,
strConnString)

dataAdapter.Fil l(dsContacts, "users")

Return dsContacts
End Function

In the GetContactsFrom CompanyForThisP roject function, I am able to hard code
a company name and successfully populate the second control but if I attempt
to pass the variable coName to the query string, it will not switch the
contact names for each company that is selected in the first control.

The controls are called out as follows:
<asp:DropDownLi st
id="ddlTo"
runat="server"
DataValueField= "cname"
AutoPostBack="T rue"
DataSource='<%# GetCompanyNames ForThisProject( ) %>'
OnSelectedIndex Changed="ddlTo_ SelectedIndexCh anged"
/>

<asp:DropDownLi st
id="ddlContact "
runat="server"
DataValueField= "name"
AutoPostBack="T rue"
DataSource='<%# GetContactsFrom CompanyForThisP roject() %>'
/>
Any replies would be extremely appreciated.
Apr 21 '06 #1
5 1838
Shouldn't it be??

querystring="SE LECT * FROM USERS WHERE CNAME = '" & var & "'"


"glenn" <gl***@discussi ons.microsoft.c om> wrote in message
news:01******** *************** ***********@mic rosoft.com...
Hi folks,

The problem I have is that a query string works if hard-coded but
if I pass a variable to it, it does not work as shown here.

This works:
querystring="SE LECT * FROM USERS WHERE CNAME = 'MICROSOFT'"

This does not work:
Dim var as string
var = "Microsoft"
querystring="SE LECT * FROM USERS WHERE CNAME = " & 'var'"

I have 2 DropDownList controls.

The first control is populated with a dataset of company names.

The second control is populated with a dataset of contact names for
the company that was selected in the first control.

The first control has an OnSelectedIndex Changed event handler.

The first control has a datasource set equal to a function named
GetCompanyNames .

The second control has a datasource set equal to a function named
GetContactNames .

In the OnSelectedIndex Changed event handler, I call the GetContactNames
function to
populate the second control with Contact Names that are associated with
the
Company
Name selected in the first control.

All is working well, but the Contact Names in the second control do not
change as
different companies are selected in the first control.

What follows is a pseudo code description of my code:

' THESE ARE CALLED AS GLOBAL VARIABLES AT TOP OF THE PAGE
Dim coName as string
Dim dsCompanyNames as DataSet = New DataSet ( )
Dim dsContacts as DataSet = New DataSet ()

' THIS IS MY OnSelectedIndex Changed EVENT HANDLER
Sub ddlTo_SelectedI ndexChanged(sen der As Object, e As EventArgs)
Dim list As DropDownList = CType(sender, DropDownList)
coName=list.Sel ectedItem.Text
GetContactsFrom CompanyForThisP roject ()
End Sub

' THIS IS MY GETCOMPANYNAMES FUNCTION
Function GetCompanyNames ForThisProject( ) as DataSet
dsCompanyNames. Clear()
Dim strConnString As String = "JET OLEDB PROVIDER AND MDB FILE"
Dim queryString As String = "SELECT COMPANYNAMES FROM USERS WHERE
PROJECT = @PROJECT"

Dim dataAdapter As New OleDbDataAdapte r (querystring, strConnString)

dataAdapter.Fil l(dsCompanyName s, "users")

Return dsCompanyNames
End Function

' THIS IS MY GETCONTACTNAMES FUNCTION
Function GetContactsFrom CompanyForThisP roject () As DataSet
dsContacts.Clea r()
Dim strConnString As String = "JET OLEDB PROVIDER AND PATH TO MDB
FILE"
Response.Write( "coName = " & coName)

Dim queryString As String

queryString = "SELECT [users].[name] FROM [users] WHERE
(([users].[cname] = '" & coName & "')" & " AND ([users].[project] = '" &
Session("projec t") & "'))"

' queryString = "SELECT [users].[name] FROM [users] WHERE
(([users]. [cname] = 'FDM') AND ([users].[project] = '" &
Session("projec t") & "'))"

Dim dataAdapter As New OleDbDataAdapte r (querystring,
strConnString)

dataAdapter.Fil l(dsContacts, "users")

Return dsContacts
End Function

In the GetContactsFrom CompanyForThisP roject function, I am able to hard
code
a company name and successfully populate the second control but if I
attempt
to pass the variable coName to the query string, it will not switch the
contact names for each company that is selected in the first control.

The controls are called out as follows:
<asp:DropDownLi st
id="ddlTo"
runat="server"
DataValueField= "cname"
AutoPostBack="T rue"
DataSource='<%# GetCompanyNames ForThisProject( ) %>'
OnSelectedIndex Changed="ddlTo_ SelectedIndexCh anged"
/>

<asp:DropDownLi st
id="ddlContact "
runat="server"
DataValueField= "name"
AutoPostBack="T rue"
DataSource='<%# GetContactsFrom CompanyForThisP roject() %>'
/>
Any replies would be extremely appreciated.

Apr 21 '06 #2
Yes, I am sorry. I wrote my pseudo code incorrectly. Your syntax
is the way my code actually reads if you follow down through my
question.

So, no it seems that it still does not work when a variable is passed.
I think it might be deeper than just the SQL statement so read on
if you can.

Thanks,
glenn

"ShaneFowlk es" wrote:
Shouldn't it be??

querystring="SE LECT * FROM USERS WHERE CNAME = '" & var & "'"


"glenn" <gl***@discussi ons.microsoft.c om> wrote in message
news:01******** *************** ***********@mic rosoft.com...
Hi folks,

The problem I have is that a query string works if hard-coded but
if I pass a variable to it, it does not work as shown here.

This works:
querystring="SE LECT * FROM USERS WHERE CNAME = 'MICROSOFT'"

This does not work:
Dim var as string
var = "Microsoft"
querystring="SE LECT * FROM USERS WHERE CNAME = " & 'var'"

I have 2 DropDownList controls.

The first control is populated with a dataset of company names.

The second control is populated with a dataset of contact names for
the company that was selected in the first control.

The first control has an OnSelectedIndex Changed event handler.

The first control has a datasource set equal to a function named
GetCompanyNames .

The second control has a datasource set equal to a function named
GetContactNames .

In the OnSelectedIndex Changed event handler, I call the GetContactNames
function to
populate the second control with Contact Names that are associated with
the
Company
Name selected in the first control.

All is working well, but the Contact Names in the second control do not
change as
different companies are selected in the first control.

What follows is a pseudo code description of my code:

' THESE ARE CALLED AS GLOBAL VARIABLES AT TOP OF THE PAGE
Dim coName as string
Dim dsCompanyNames as DataSet = New DataSet ( )
Dim dsContacts as DataSet = New DataSet ()

' THIS IS MY OnSelectedIndex Changed EVENT HANDLER
Sub ddlTo_SelectedI ndexChanged(sen der As Object, e As EventArgs)
Dim list As DropDownList = CType(sender, DropDownList)
coName=list.Sel ectedItem.Text
GetContactsFrom CompanyForThisP roject ()
End Sub

' THIS IS MY GETCOMPANYNAMES FUNCTION
Function GetCompanyNames ForThisProject( ) as DataSet
dsCompanyNames. Clear()
Dim strConnString As String = "JET OLEDB PROVIDER AND MDB FILE"
Dim queryString As String = "SELECT COMPANYNAMES FROM USERS WHERE
PROJECT = @PROJECT"

Dim dataAdapter As New OleDbDataAdapte r (querystring, strConnString)

dataAdapter.Fil l(dsCompanyName s, "users")

Return dsCompanyNames
End Function

' THIS IS MY GETCONTACTNAMES FUNCTION
Function GetContactsFrom CompanyForThisP roject () As DataSet
dsContacts.Clea r()
Dim strConnString As String = "JET OLEDB PROVIDER AND PATH TO MDB
FILE"
Response.Write( "coName = " & coName)

Dim queryString As String

queryString = "SELECT [users].[name] FROM [users] WHERE
(([users].[cname] = '" & coName & "')" & " AND ([users].[project] = '" &
Session("projec t") & "'))"

' queryString = "SELECT [users].[name] FROM [users] WHERE
(([users]. [cname] = 'FDM') AND ([users].[project] = '" &
Session("projec t") & "'))"

Dim dataAdapter As New OleDbDataAdapte r (querystring,
strConnString)

dataAdapter.Fil l(dsContacts, "users")

Return dsContacts
End Function

In the GetContactsFrom CompanyForThisP roject function, I am able to hard
code
a company name and successfully populate the second control but if I
attempt
to pass the variable coName to the query string, it will not switch the
contact names for each company that is selected in the first control.

The controls are called out as follows:
<asp:DropDownLi st
id="ddlTo"
runat="server"
DataValueField= "cname"
AutoPostBack="T rue"
DataSource='<%# GetCompanyNames ForThisProject( ) %>'
OnSelectedIndex Changed="ddlTo_ SelectedIndexCh anged"
/>

<asp:DropDownLi st
id="ddlContact "
runat="server"
DataValueField= "name"
AutoPostBack="T rue"
DataSource='<%# GetContactsFrom CompanyForThisP roject() %>'
/>
Any replies would be extremely appreciated.


Apr 21 '06 #3
Found what seemed to be in err in my SQL statement that passes a variable
but the change still did not work.

Here it is:
queryString = "SELECT [users].[name] FROM [users] WHERE
(([users].[cname] = '" & coName & "') AND ([users].[project] = '" &
Session("projec t") & "'))"

"glenn" wrote:
Yes, I am sorry. I wrote my pseudo code incorrectly. Your syntax
is the way my code actually reads if you follow down through my
question.

So, no it seems that it still does not work when a variable is passed.
I think it might be deeper than just the SQL statement so read on
if you can.

Thanks,
glenn

"ShaneFowlk es" wrote:
Shouldn't it be??

querystring="SE LECT * FROM USERS WHERE CNAME = '" & var & "'"


"glenn" <gl***@discussi ons.microsoft.c om> wrote in message
news:01******** *************** ***********@mic rosoft.com...
Hi folks,

The problem I have is that a query string works if hard-coded but
if I pass a variable to it, it does not work as shown here.

This works:
querystring="SE LECT * FROM USERS WHERE CNAME = 'MICROSOFT'"

This does not work:
Dim var as string
var = "Microsoft"
querystring="SE LECT * FROM USERS WHERE CNAME = " & 'var'"

I have 2 DropDownList controls.

The first control is populated with a dataset of company names.

The second control is populated with a dataset of contact names for
the company that was selected in the first control.

The first control has an OnSelectedIndex Changed event handler.

The first control has a datasource set equal to a function named
GetCompanyNames .

The second control has a datasource set equal to a function named
GetContactNames .

In the OnSelectedIndex Changed event handler, I call the GetContactNames
function to
populate the second control with Contact Names that are associated with
the
Company
Name selected in the first control.

All is working well, but the Contact Names in the second control do not
change as
different companies are selected in the first control.

What follows is a pseudo code description of my code:

' THESE ARE CALLED AS GLOBAL VARIABLES AT TOP OF THE PAGE
Dim coName as string
Dim dsCompanyNames as DataSet = New DataSet ( )
Dim dsContacts as DataSet = New DataSet ()

' THIS IS MY OnSelectedIndex Changed EVENT HANDLER
Sub ddlTo_SelectedI ndexChanged(sen der As Object, e As EventArgs)
Dim list As DropDownList = CType(sender, DropDownList)
coName=list.Sel ectedItem.Text
GetContactsFrom CompanyForThisP roject ()
End Sub

' THIS IS MY GETCOMPANYNAMES FUNCTION
Function GetCompanyNames ForThisProject( ) as DataSet
dsCompanyNames. Clear()
Dim strConnString As String = "JET OLEDB PROVIDER AND MDB FILE"
Dim queryString As String = "SELECT COMPANYNAMES FROM USERS WHERE
PROJECT = @PROJECT"

Dim dataAdapter As New OleDbDataAdapte r (querystring, strConnString)

dataAdapter.Fil l(dsCompanyName s, "users")

Return dsCompanyNames
End Function

' THIS IS MY GETCONTACTNAMES FUNCTION
Function GetContactsFrom CompanyForThisP roject () As DataSet
dsContacts.Clea r()
Dim strConnString As String = "JET OLEDB PROVIDER AND PATH TO MDB
FILE"
Response.Write( "coName = " & coName)

Dim queryString As String

queryString = "SELECT [users].[name] FROM [users] WHERE
(([users].[cname] = '" & coName & "')" & " AND ([users].[project] = '" &
Session("projec t") & "'))"

' queryString = "SELECT [users].[name] FROM [users] WHERE
(([users]. [cname] = 'FDM') AND ([users].[project] = '" &
Session("projec t") & "'))"

Dim dataAdapter As New OleDbDataAdapte r (querystring,
strConnString)

dataAdapter.Fil l(dsContacts, "users")

Return dsContacts
End Function

In the GetContactsFrom CompanyForThisP roject function, I am able to hard
code
a company name and successfully populate the second control but if I
attempt
to pass the variable coName to the query string, it will not switch the
contact names for each company that is selected in the first control.

The controls are called out as follows:
<asp:DropDownLi st
id="ddlTo"
runat="server"
DataValueField= "cname"
AutoPostBack="T rue"
DataSource='<%# GetCompanyNames ForThisProject( ) %>'
OnSelectedIndex Changed="ddlTo_ SelectedIndexCh anged"
/>

<asp:DropDownLi st
id="ddlContact "
runat="server"
DataValueField= "name"
AutoPostBack="T rue"
DataSource='<%# GetContactsFrom CompanyForThisP roject() %>'
/>
Any replies would be extremely appreciated.


Apr 21 '06 #4
It is bad practice to build your SQL queries this way as it leaves you code
vulnerable to SQL injection exploits. You should use parameters in your SQL
stament such as

"SELECT field1, field2, field3 from table1 where field3 = @ParameterName"
"glenn" wrote:
Found what seemed to be in err in my SQL statement that passes a variable
but the change still did not work.

Here it is:
queryString = "SELECT [users].[name] FROM [users] WHERE
(([users].[cname] = '" & coName & "') AND ([users].[project] = '" &
Session("projec t") & "'))"

"glenn" wrote:
Yes, I am sorry. I wrote my pseudo code incorrectly. Your syntax
is the way my code actually reads if you follow down through my
question.

So, no it seems that it still does not work when a variable is passed.
I think it might be deeper than just the SQL statement so read on
if you can.

Thanks,
glenn

"ShaneFowlk es" wrote:
Shouldn't it be??

querystring="SE LECT * FROM USERS WHERE CNAME = '" & var & "'"


"glenn" <gl***@discussi ons.microsoft.c om> wrote in message
news:01******** *************** ***********@mic rosoft.com...
> Hi folks,
>
> The problem I have is that a query string works if hard-coded but
> if I pass a variable to it, it does not work as shown here.
>
> This works:
> querystring="SE LECT * FROM USERS WHERE CNAME = 'MICROSOFT'"
>
> This does not work:
> Dim var as string
> var = "Microsoft"
> querystring="SE LECT * FROM USERS WHERE CNAME = " & 'var'"
>
> I have 2 DropDownList controls.
>
> The first control is populated with a dataset of company names.
>
> The second control is populated with a dataset of contact names for
> the company that was selected in the first control.
>
> The first control has an OnSelectedIndex Changed event handler.
>
> The first control has a datasource set equal to a function named
> GetCompanyNames .
>
> The second control has a datasource set equal to a function named
> GetContactNames .
>
> In the OnSelectedIndex Changed event handler, I call the GetContactNames
> function to
> populate the second control with Contact Names that are associated with
> the
> Company
> Name selected in the first control.
>
> All is working well, but the Contact Names in the second control do not
> change as
> different companies are selected in the first control.
>
> What follows is a pseudo code description of my code:
>
> ' THESE ARE CALLED AS GLOBAL VARIABLES AT TOP OF THE PAGE
> Dim coName as string
> Dim dsCompanyNames as DataSet = New DataSet ( )
> Dim dsContacts as DataSet = New DataSet ()
>
> ' THIS IS MY OnSelectedIndex Changed EVENT HANDLER
> Sub ddlTo_SelectedI ndexChanged(sen der As Object, e As EventArgs)
> Dim list As DropDownList = CType(sender, DropDownList)
> coName=list.Sel ectedItem.Text
> GetContactsFrom CompanyForThisP roject ()
> End Sub
>
> ' THIS IS MY GETCOMPANYNAMES FUNCTION
> Function GetCompanyNames ForThisProject( ) as DataSet
> dsCompanyNames. Clear()
> Dim strConnString As String = "JET OLEDB PROVIDER AND MDB FILE"
> Dim queryString As String = "SELECT COMPANYNAMES FROM USERS WHERE
> PROJECT = @PROJECT"
>
> Dim dataAdapter As New OleDbDataAdapte r (querystring, strConnString)
>
> dataAdapter.Fil l(dsCompanyName s, "users")
>
> Return dsCompanyNames
> End Function
>
> ' THIS IS MY GETCONTACTNAMES FUNCTION
> Function GetContactsFrom CompanyForThisP roject () As DataSet
> dsContacts.Clea r()
> Dim strConnString As String = "JET OLEDB PROVIDER AND PATH TO MDB
> FILE"
> Response.Write( "coName = " & coName)
>
> Dim queryString As String
>
> queryString = "SELECT [users].[name] FROM [users] WHERE
> (([users].[cname] = '" & coName & "')" & " AND ([users].[project] = '" &
> Session("projec t") & "'))"
>
> ' queryString = "SELECT [users].[name] FROM [users] WHERE
> (([users]. [cname] = 'FDM') AND ([users].[project] = '" &
> Session("projec t") & "'))"
>
> Dim dataAdapter As New OleDbDataAdapte r (querystring,
> strConnString)
>
> dataAdapter.Fil l(dsContacts, "users")
>
> Return dsContacts
> End Function
>
> In the GetContactsFrom CompanyForThisP roject function, I am able to hard
> code
> a company name and successfully populate the second control but if I
> attempt
> to pass the variable coName to the query string, it will not switch the
> contact names for each company that is selected in the first control.
>
> The controls are called out as follows:
> <asp:DropDownLi st
> id="ddlTo"
> runat="server"
> DataValueField= "cname"
> AutoPostBack="T rue"
> DataSource='<%# GetCompanyNames ForThisProject( ) %>'
> OnSelectedIndex Changed="ddlTo_ SelectedIndexCh anged"
> />
>
> <asp:DropDownLi st
> id="ddlContact "
> runat="server"
> DataValueField= "name"
> AutoPostBack="T rue"
> DataSource='<%# GetContactsFrom CompanyForThisP roject() %>'
> />
>
>
> Any replies would be extremely appreciated.

Apr 21 '06 #5
Response.write your sql statement. We have no way of knowing the values of
your variables

Jeff
"glenn" <gl***@discussi ons.microsoft.c om> wrote in message
news:8F******** *************** ***********@mic rosoft.com...
Found what seemed to be in err in my SQL statement that passes a variable
but the change still did not work.

Here it is:
queryString = "SELECT [users].[name] FROM [users] WHERE
(([users].[cname] = '" & coName & "') AND ([users].[project] = '" &
Session("projec t") & "'))"

"glenn" wrote:
Yes, I am sorry. I wrote my pseudo code incorrectly. Your syntax
is the way my code actually reads if you follow down through my
question.

So, no it seems that it still does not work when a variable is passed.
I think it might be deeper than just the SQL statement so read on
if you can.

Thanks,
glenn

"ShaneFowlk es" wrote:
> Shouldn't it be??
>
> querystring="SE LECT * FROM USERS WHERE CNAME = '" & var & "'"
>
>
>
>
> "glenn" <gl***@discussi ons.microsoft.c om> wrote in message
> news:01******** *************** ***********@mic rosoft.com...
> > Hi folks,
> >
> > The problem I have is that a query string works if hard-coded but
> > if I pass a variable to it, it does not work as shown here.
> >
> > This works:
> > querystring="SE LECT * FROM USERS WHERE CNAME = 'MICROSOFT'"
> >
> > This does not work:
> > Dim var as string
> > var = "Microsoft"
> > querystring="SE LECT * FROM USERS WHERE CNAME = " & 'var'"
> >
> > I have 2 DropDownList controls.
> >
> > The first control is populated with a dataset of company names.
> >
> > The second control is populated with a dataset of contact names for
> > the company that was selected in the first control.
> >
> > The first control has an OnSelectedIndex Changed event handler.
> >
> > The first control has a datasource set equal to a function named
> > GetCompanyNames .
> >
> > The second control has a datasource set equal to a function named
> > GetContactNames .
> >
> > In the OnSelectedIndex Changed event handler, I call the
> > GetContactNames
> > function to
> > populate the second control with Contact Names that are associated
> > with
> > the
> > Company
> > Name selected in the first control.
> >
> > All is working well, but the Contact Names in the second control do
> > not
> > change as
> > different companies are selected in the first control.
> >
> > What follows is a pseudo code description of my code:
> >
> > ' THESE ARE CALLED AS GLOBAL VARIABLES AT TOP OF THE PAGE
> > Dim coName as string
> > Dim dsCompanyNames as DataSet = New DataSet ( )
> > Dim dsContacts as DataSet = New DataSet ()
> >
> > ' THIS IS MY OnSelectedIndex Changed EVENT HANDLER
> > Sub ddlTo_SelectedI ndexChanged(sen der As Object, e As EventArgs)
> > Dim list As DropDownList = CType(sender, DropDownList)
> > coName=list.Sel ectedItem.Text
> > GetContactsFrom CompanyForThisP roject ()
> > End Sub
> >
> > ' THIS IS MY GETCOMPANYNAMES FUNCTION
> > Function GetCompanyNames ForThisProject( ) as DataSet
> > dsCompanyNames. Clear()
> > Dim strConnString As String = "JET OLEDB PROVIDER AND MDB FILE"
> > Dim queryString As String = "SELECT COMPANYNAMES FROM USERS
> > WHERE
> > PROJECT = @PROJECT"
> >
> > Dim dataAdapter As New OleDbDataAdapte r (querystring,
> > strConnString)
> >
> > dataAdapter.Fil l(dsCompanyName s, "users")
> >
> > Return dsCompanyNames
> > End Function
> >
> > ' THIS IS MY GETCONTACTNAMES FUNCTION
> > Function GetContactsFrom CompanyForThisP roject () As DataSet
> > dsContacts.Clea r()
> > Dim strConnString As String = "JET OLEDB PROVIDER AND PATH TO
> > MDB
> > FILE"
> > Response.Write( "coName = " & coName)
> >
> > Dim queryString As String
> >
> > queryString = "SELECT [users].[name] FROM [users] WHERE
> > (([users].[cname] = '" & coName & "')" & " AND ([users].[project] =
> > '" &
> > Session("projec t") & "'))"
> >
> > ' queryString = "SELECT [users].[name] FROM [users] WHERE
> > (([users]. [cname] = 'FDM') AND ([users].[project] = '" &
> > Session("projec t") & "'))"
> >
> > Dim dataAdapter As New OleDbDataAdapte r (querystring,
> > strConnString)
> >
> > dataAdapter.Fil l(dsContacts, "users")
> >
> > Return dsContacts
> > End Function
> >
> > In the GetContactsFrom CompanyForThisP roject function, I am able to
> > hard
> > code
> > a company name and successfully populate the second control but if I
> > attempt
> > to pass the variable coName to the query string, it will not switch
> > the
> > contact names for each company that is selected in the first control.
> >
> > The controls are called out as follows:
> > <asp:DropDownLi st
> > id="ddlTo"
> > runat="server"
> > DataValueField= "cname"
> > AutoPostBack="T rue"
> > DataSource='<%# GetCompanyNames ForThisProject( ) %>'
> > OnSelectedIndex Changed="ddlTo_ SelectedIndexCh anged"
> > />
> >
> > <asp:DropDownLi st
> > id="ddlContact "
> > runat="server"
> > DataValueField= "name"
> > AutoPostBack="T rue"
> > DataSource='<%# GetContactsFrom CompanyForThisP roject() %>'
> > />
> >
> >
> > Any replies would be extremely appreciated.
>
>
>

Apr 21 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
14968
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
58
10204
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of code... TCHAR myArray; DoStuff(myArray);
39
7689
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down indicate: a) That I don't know enough b) Passing arguments by ref is bad
17
9399
by: LP | last post by:
Hello, Here's the scenario: Object A opens a Sql Db connection to execute number of SqlCommands. Then it needs to pass this connection to a constructor of object B which in turn executes more commands on the same connection. I have an understanding that if SqlConnection is passed as "value" (unboxed), object B will create its own copy of SqlConnection, so when object A closes its connection, it remains open for object B's copy. Is this
6
3265
by: Scott Zabolotzky | last post by:
I'm trying to pass a custom object back and forth between forms. This custom object is pulled into the app using an external reference to an assembly DLL that was given to me by a co-worker. A query-string flag is used to indicate to the page whether it should instantiate a new instance of the object or access an existing instance from the calling page. On the both pages I have a property of the page which is an instance of this custom...
3
1992
by: James Robertson | last post by:
I am new to the ASP and VB thing so be kind. Question I have is that I have created an ASPX web site to use as an E-Mail page. But I want to use this for a lot of users. Can I create the link on the WEB site to mail to passing a variable from the WEB site to the ASPX web site to E-Mail to? Hope I explained this correctly. This is a response from another group. There was no way for you to know it, but this is a classic asp newsgroup....
11
3832
by: kennthompson | last post by:
Trouble passing mysql table name in php. If I use an existing table name already defined everything works fine as the following script illustrates. <?php function fms_get_info() { $result = mysql_query("select * from $tableInfo") ; for ($i = 0; $i < mysql_num_rows($result); $i++) {
5
9860
by: moni | last post by:
Hi.. I am trying to use javascript for google maps display. If I call the javascript function from my aspx file I use: <input type="text" id="addresstext" value="Huntington Avenue, Boston, MA" name="yourName" style="width: 287px" />
11
6174
by: =?Utf-8?B?U3VqZWV0?= | last post by:
If there are long strings (like 1MB or 2MB) is it more performant to pass those by ref to methods or by value?
0
9855
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9697
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10649
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10295
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9426
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7829
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7018
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4487
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3136
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.