2014-10-13 2 views
1

세션을 사용하여 일부 변수를 다음 페이지 "ProcedureSelectionForm.aspx"로 보내려고합니다. 보시다시피 세션은 주석 처리되었습니다. 아래의 코드는 작동합니다 (변수를 보내지 않고). 그러나 주석을 제거하면 .onclick 함수가 "ProcedureSelectionForm.aspx"로 이동하지 않고 페이지를 다시로드합니다. 이런 이유로, 나는 이것이 나의 문제가있는 곳이라고 생각한다. 처음 두 열은 데이터베이스의 "Account"와 "Password"입니다. 나는 철자가 틀리지 않았다. 나는 VB와 ASP.net을 처음 사용하고 있으며, 무슨 일이 일어나고 있는지, 왜 내가 원하는 기능이 실현되지 않는지에 대한 설명을 해줄 것이다. 도와 줘서 고마워!SQL/문제 해결 세션 변수 비교

If IsValid Then 
       Try 
        Dim strSQL = "select * from CreatePatient where Account = @Account and Password = @Password" 
         Using CCSQL = New SqlConnection(ConfigurationManager.ConnectionStrings("CreatePatientConnectionString").ConnectionString) 
          Using CCUser = New SqlCommand(strSQL, CCSQL) 
           CCSQL.Open() 
           CCUser.Parameters.Add("@Account", Data.SqlDbType.VarChar).Value = PatientAccount.Text 
           CCUser.Parameters.Add("@Password", Data.SqlDbType.VarChar).Value = PatientPass.Text 
           CCUser.ExecuteNonQuery() 

          'Using reader As SqlDataReader = CCUser.ExecuteReader() 
          'If reader.HasRows Then 
          'reader.Read() 
          'Session("user") = reader("Account") 
          'Session("pass") = reader("Password") 
          Response.Redirect("ProcedureSelectionForm.aspx") 
          'End If 
          'End Using 
         End Using 
        End Using 
       Catch ex As Exception 
        Label1.Text = ex.Message 
       End Try 
      End If 
+0

주석 처리를 제거하면 .onclick 함수가 "ProcedureSelectionForm.aspx"로 이동하지 않고 페이지를 다시로드합니다. - 코드를 디버깅하여 실제로 해당 섹션에 도달했는지 확인 했습니까? re :'PostValue'에'IsValid'가 있습니까? [단계별 디버그] (http://msdn.microsoft.com/en-us/library/y740d9d3.aspx)를 사용하면 왜 작동하지 않는지에 대해 자세히 알 수 있습니다. – EdSF

+0

예. 줄을 주석으로 처리하고 "ProcedureSelectionForm.aspx"로 이동합니다. 내 문제는 데이터베이스에서 읽으려고하는 것입니다. 데이터베이스에 대한 연결이 열려 있습니다. 링크를 주셔서 감사합니다. 참고로 사용하겠습니다. –

답변

-1

당신은 당신이 실제로 쿼리 (즉, SQL 또한 "SELECT"문. 당신은 .ExecuteReader() 그 두 값을 읽을 다만 할 수 있습니다. 을 수행 할 때 .ExecuteNonQuery() 싶지 않아, 나는 당신이 가정 계정 및 암호를 확인하려고,.. 그렇지 않으면 당신은 단지 Session("user") = PatientAccount.Text을 설정하고 Session("pass") = PatientPass.Text을 설정할 수

+0

감사합니다. 내가 제안한 변경 사항을 적용했습니다. 그것은 내 문제를 해결하지 못했지만 효율적인 코드는 언제나 환영합니다. –

1

내 친구가 된 시간을 만들 수있게하는 것은 저를 도와 나는 닫는 연결 외에 그가 다른 무엇을했는지 확실치

If IsValid Then 
      Dim CCSQL As New SqlConnection 
      Dim CCUser As New SqlCommand 
      Dim strSQL As String 
      Dim dtrUser As SqlDataReader 
      Try 
       CCSQL.ConnectionString = ConfigurationManager.ConnectionStrings("CreatePatientConnectionString").ConnectionString 
       strSQL = "Select * from CreatePatient where [email protected] and [email protected]" 
       CCUser.CommandType = Data.CommandType.Text 
       CCUser.CommandText = strSQL 
       CCUser.Parameters.Add("@user", Data.SqlDbType.VarChar).Value = PatientAccount.Text 
       CCUser.Parameters.Add("@pwd", Data.SqlDbType.VarChar).Value = PatientPass.Text 

       CCSQL.Open() 
       CCUser.Connection = CCSQL 
       dtrUser = CCUser.ExecuteReader() 
       If dtrUser.HasRows Then 
        dtrUser.Read() 
        Session("user") = dtrUser("Account") 
        Session("level") = dtrUser("Password") 


        Response.Redirect("ProcedureSelectionForm.aspx") 

       Else 
        Label1.Text = "Please check your user name and password" 

       End If 
       dtrUser.Close() 
       CCSQL.Close() 
      Catch ex As Exception 
       Label1.Text = ex.Message 
      End Try 
     End If 

마감 기한이 맞지만 답변에 관심이있는 사람들에게 돌아갑니다. 당신의 노고에 감사드립니다.