|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
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")
Show quote
Hide quote
"Newbie" <New***@discussions.microsoft.com> wrote in message Hello Newbie,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") > 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 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 > > > > 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. -- Show quoteHide quote- Nicholas Paldino [.NET/C# MVP] - mvp@spam.guard.caspershouse.com "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") > >
Other interesting topics
Why exception when going through the DataSet?
How to show a datetime field in a TextBox Convetting string/text to datetime Question about Sockets Problem with deriving System.EventArgs setting security from code C# as IE Control Invoke on Dialog not yet shown Programmatically retrieving photos ComboBox find item based on value |
|||||||||||||||||||||||