我正在爲我的項目登錄頁面,但運行時出現錯誤「位置0沒有行」。 我試過這些代碼行。如何處理空數據集?
Imports System.Data.SqlClient
Imports System.Data
Partial Class Dept_login
Inherits System.Web.UI.Page
Protected Sub BtnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnSubmit.Click
Dim ds As New DataSet
'Try
Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("VMSConnectionString").ConnectionString)
con.Open()
Dim cmd As New SqlCommand("SELECT password FROM Dept_login WHERE user_id='" + Txtuname.Text + "'", con)
Dim da As New SqlDataAdapter(cmd)
da.Fill(ds)
If Not IsDBNull(ds) Then
If Txtpwd.Text = ds.Tables(0).Rows(0).Item("password") Then
Response.Redirect("Online Services.aspx") 'the page i want to redirect to after login successful
Else
Label1.Visible = True 'initially visible is false and text is INVALID PASSWORD
End If
con.Close()
' Catch ex As Exception
' End Try
End If
End Sub
Private Function Dept_login() As Integer
Throw New NotImplementedException
End Function
End Class
選擇一個更好的標題! –
Aslo,這不是MVC。 –
plz現在幫助我,我明天需要向我的老師展示這個項目。 – user3030098