We help IT Professionals succeed at work.
Get Started

SQL Query not working in webform?

narmi2
narmi2 asked
on
213 Views
Last Modified: 2010-04-07
Hi

I'm having problems with this sub.  When i run the sql query in this sub in query analyser, it returns 1 email e.g. narmi@home.com
But when I run the following sub on page load of my webform, it only returns the word "email" in the textbox1.

Anyone know why this is happening?

'-------------THE CODE STARTS HERE---------------
    Sub EmailSender()
        Dim xCN As String = Request.ServerVariables("LOGON_USER")
        Dim xllength As Integer = xCN.Length
        Dim xemp_code As String = xCN.Substring(xllength - 3, 3)

        Dim TestURL As String = "../employees/basic_details.aspx"

        objSelectDataAdapter = New SqlDataAdapter("SELECT CASE WHEN tb2_from_db1.internet_addr is null THEN " & _
            "lower(tb2_from_db1.first_name) + '.' + lower(tb2_from_db1.last_name) + '@home.com' " & _
            "WHEN tb2_from_db1.internet_addr like '%post%' THEN " & _
            "lower(tb2_from_db1.first_name) + '.' + lower(tb2_from_db1.last_name) + '@home.com' " & _
            "ELSE lower(tb2_from_db1.internet_addr) " & _
            "END As [email] " & _
            "FROM db1.dbo.hbm_persnl tb1_from_db1, " & _
            "db1.dbo.hbm_name tb2_from_db1, " & _
            "db2.dbo.ps_tb1_from_db2_emails tb1_from_db2, " & _
            "db2.dbo.ps_task_sub(tb2_from_db2) " & _
            "WHERE(tb1_from_db1.name_uno = tb2_from_db1.name_uno) " & _
            "AND tb1_from_db1.employee_code = tb1_from_db2.cms_user " & _
            "AND tb2_from_db2.sub_task_id = tb1_from_db2.sub_task_id " & _
            "AND len(tb1_from_db1.employee_code) = 3  " & _
            "AND tb1_from_db2.inactive = 0 " & _
            "AND tb2_from_db2.inactive = 0 " & _
            "AND tb1_from_db1._leaver = 'n'  " & _
            "AND tb1_from_db2.email_sender = 1 " & _
            "AND tb1_from_db1.employee_code = 'narmi' " & _
            "AND tb2_from_db2.sub_task_url = '../pages/intro.aspx'", objConnection)

        objDataSet = New DataSet()
        objSelectDataAdapter.Fill(objDataSet, "DSEmails")

        Response.Write("URL: " & TestURL & "<br />")
        Response.Write("EMP: " & xemp_code)

        TextBox1.Text = objDataSet.Tables("DSEmails").Columns("email").ColumnName.ToString()
    End Sub
'-------------THE CODE ENDS HERE---------------

URGENT 500 Points!
Thanks
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE