Home All Groups Group Topic Archive Search About
Author
28 Mar 2005 3:09 PM
Newbie
Hi!

I need to convert the select statement below from VB ASP to C# ASP.NET. Pls.
help and thanks in advance.

' Create recordset and query

Set rsCHI = Server.CreateObject("ADODB.Recordset")

sCHI = "SELECT a.cust_des1, a.des1 projectName, b.job_no JobNo, b.des1
jobName, b.contract_amt, " _
& "b.est_start_date,b.est_completion_date " _
& "FROM pa_project_master a, pa_job b " _
& "WHERE b.project_no = '" & Request("projectNo") & "' " _
& " And a.project_no = b.project_no " _
& " And b.job_no in (select job_no from pa_security where emp_no = '" &
Session("userempno") & "' "_
& " And project_no= '" & Request("projectNo") & "')"

' Open recordset and run query
rsCHI.Open sCHI,db,,,adCmdText

If rsCHI.EOF Then
    Response.Redirect("donf.asp")
End if
    Response.Expires = 0

' Set customer session variable
Session("customer") = rsCHI("cust_des1")
detailJobNo = rsCHI("jobNo")

Author
28 Mar 2005 3:50 PM
J. Buelna - Houston, TX
Show quote Hide quote
"Newbie" <New***@discussions.microsoft.com> wrote in message
news:2A172A77-67B4-4ABD-93DF-AFDBFDB9E111@microsoft.com...
> Hi!
>
> I need to convert the select statement below from VB ASP to C# ASP.NET.
> Pls.
> help and thanks in advance.
>
> ' Create recordset and query
>
> Set rsCHI = Server.CreateObject("ADODB.Recordset")
>
> sCHI = "SELECT a.cust_des1, a.des1 projectName, b.job_no JobNo, b.des1
> jobName, b.contract_amt, " _
> & "b.est_start_date,b.est_completion_date " _
> & "FROM pa_project_master a, pa_job b " _
> & "WHERE b.project_no = '" & Request("projectNo") & "' " _
> & " And a.project_no = b.project_no " _
> & " And b.job_no in (select job_no from pa_security where emp_no = '" &
> Session("userempno") & "' "_
> & " And project_no= '" & Request("projectNo") & "')"
>
> ' Open recordset and run query
> rsCHI.Open sCHI,db,,,adCmdText
>
> If rsCHI.EOF Then
> Response.Redirect("donf.asp")
> End if
> Response.Expires = 0
>
> ' Set customer session variable
> Session("customer") = rsCHI("cust_des1")
> detailJobNo = rsCHI("jobNo")
>


Hello Newbie,

Here is the select statement, as you requested:

string commandText = @"SELECT a.cust_des1, a.des1 projectName,
b.job_no JobNo, b.des1 jobName, b.contract_amt,
b.est_start_date,b.est_completion_date
FROM pa_project_master a INNER JOIN pa_job b
ON a.project_no = b.project_no
WHERE b.project_no = '" + componentProjectNumber.Text + @"'
AND b.job_no in (select job_no from pa_security where emp_no = '" +
Session["userempno"] + @"' AND project_no= '" +
componentProjectNumber.Text + "')";

Of course, you should santize the user input to prevent query injections.
You could use a parameterized sql statement.

I changed your join for performance reasons.

There are plenty of learning resources out there...

J. Buelna - Houston, TX
Are all your drivers up to date? click for free checkup

Author
28 Mar 2005 4:27 PM
Newbie
Thanks for your help J. Buelna,

I also need to convert:

' Set customer session variable
Session("customer") = rsCHI("cust_des1")
detailJobNo = rsCHI("jobNo")



Show quoteHide quote
"J. Buelna - Houston, TX" wrote:

>
> "Newbie" <New***@discussions.microsoft.com> wrote in message
> news:2A172A77-67B4-4ABD-93DF-AFDBFDB9E111@microsoft.com...
> > Hi!
> >
> > I need to convert the select statement below from VB ASP to C# ASP.NET.
> > Pls.
> > help and thanks in advance.
> >
> > ' Create recordset and query
> >
> > Set rsCHI = Server.CreateObject("ADODB.Recordset")
> >
> > sCHI = "SELECT a.cust_des1, a.des1 projectName, b.job_no JobNo, b.des1
> > jobName, b.contract_amt, " _
> > & "b.est_start_date,b.est_completion_date " _
> > & "FROM pa_project_master a, pa_job b " _
> > & "WHERE b.project_no = '" & Request("projectNo") & "' " _
> > & " And a.project_no = b.project_no " _
> > & " And b.job_no in (select job_no from pa_security where emp_no = '" &
> > Session("userempno") & "' "_
> > & " And project_no= '" & Request("projectNo") & "')"
> >
> > ' Open recordset and run query
> > rsCHI.Open sCHI,db,,,adCmdText
> >
> > If rsCHI.EOF Then
> > Response.Redirect("donf.asp")
> > End if
> > Response.Expires = 0
> >
> > ' Set customer session variable
> > Session("customer") = rsCHI("cust_des1")
> > detailJobNo = rsCHI("jobNo")
> >
>
>
> Hello Newbie,
>
> Here is the select statement, as you requested:
>
> string commandText = @"SELECT a.cust_des1, a.des1 projectName,
> b.job_no JobNo, b.des1 jobName, b.contract_amt,
> b.est_start_date,b.est_completion_date
> FROM pa_project_master a INNER JOIN pa_job b
> ON a.project_no = b.project_no
> WHERE b.project_no = '" + componentProjectNumber.Text + @"'
> AND b.job_no in (select job_no from pa_security where emp_no = '" +
> Session["userempno"] + @"' AND project_no= '" +
> componentProjectNumber.Text + "')";
>
> Of course, you should santize the user input to prevent query injections.
> You could use a parameterized sql statement.
>
> I changed your join for performance reasons.
>
> There are plenty of learning resources out there...
>
> J. Buelna - Houston, TX
>
>
>
>
Author
28 Mar 2005 3:53 PM
Nicholas Paldino [.NET/C# MVP]
Newbie,

    Are you looking to use the data access classes in .NET to access the
data, or are you looking to use ADO still?  If you are looking to use ADO,
then most of the code will be the same, as the inherent objects in ASP.NET
are pretty much the same as ASP.

    If you change to use the classes in the System.Data namespace, then you
will have to change how you create the query, and what objects you use.

    Also, you should not be constructing the query string as you do.  You
open yourself up to injection attacks.  Use parameterized queries instead.


--
               - Nicholas Paldino [.NET/C# MVP]
               - mvp@spam.guard.caspershouse.com

Show quoteHide quote
"Newbie" <New***@discussions.microsoft.com> wrote in message
news:2A172A77-67B4-4ABD-93DF-AFDBFDB9E111@microsoft.com...
> Hi!
>
> I need to convert the select statement below from VB ASP to C# ASP.NET.
> Pls.
> help and thanks in advance.
>
> ' Create recordset and query
>
> Set rsCHI = Server.CreateObject("ADODB.Recordset")
>
> sCHI = "SELECT a.cust_des1, a.des1 projectName, b.job_no JobNo, b.des1
> jobName, b.contract_amt, " _
> & "b.est_start_date,b.est_completion_date " _
> & "FROM pa_project_master a, pa_job b " _
> & "WHERE b.project_no = '" & Request("projectNo") & "' " _
> & " And a.project_no = b.project_no " _
> & " And b.job_no in (select job_no from pa_security where emp_no = '" &
> Session("userempno") & "' "_
> & " And project_no= '" & Request("projectNo") & "')"
>
> ' Open recordset and run query
> rsCHI.Open sCHI,db,,,adCmdText
>
> If rsCHI.EOF Then
> Response.Redirect("donf.asp")
> End if
> Response.Expires = 0
>
> ' Set customer session variable
> Session("customer") = rsCHI("cust_des1")
> detailJobNo = rsCHI("jobNo")
>
>

Bookmark and Share