Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > VB.NET ดูโค้ดหน้า Login ให้หน่อยครับ รันไม่ผ่านเวลาใส่รหัสหรือ ไอดีผิดครับ



 

VB.NET ดูโค้ดหน้า Login ให้หน่อยครับ รันไม่ผ่านเวลาใส่รหัสหรือ ไอดีผิดครับ

 



Topic : 074551



โพสกระทู้ ( 23 )
บทความ ( 0 )



สถานะออฟไลน์




ของผมถ้าใส่รหัสและไอดีถูก สามารถใช้ได้ แต่ พอใส่รหัสผิดหรือไอดีผิด หรือไม่ใส่อย่างใดอย่างหนึ่ง มันเออเร่อเลยครับ แก้ไงดีครับ
มันจะเออเร่อตรงบรรทัดที่ 56 ครับ

Code (VB.NET)
Imports System.Data
Imports System.Data.SqlServerCe





Public Class Login
    Dim Cnn As New SqlCeConnection(Cnnstring)
    Dim Cnnstring As String
    Dim sqlselect As String
    Dim sqlreader As SqlCeDataReader
    Dim userida As String
    Dim passida As String
    Dim myConnection As SqlCeConnection = New SqlCeConnection("Data source=D:\Project New\WindowsApplication1\WindowsApplication1\Database1.sdf;")
    Dim myCommand As SqlCeCommand
    Dim myConn As SqlCeCommand
    Dim cmdString As String


    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click

        
        With Cnn
            If .State = ConnectionState.Open Then Close()
            .ConnectionString = Cnnstring
            myConnection.Open()
            myConnection.Close()
        End With
        If txtuser_ID.Text = "" And txtpassword.Text = "" Then
            MessageBox.Show("ใส่ข้อมูล", "No userID", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Else
            ReadMyData(Cnnstring)
        End If


    End Sub

   
    Public Sub readmydata(ByVal myConnString As String)
        On Error GoTo 0
        With Cnn
            If .State = ConnectionState.Open Then Close()
            .ConnectionString = Cnnstring
            myConnection.Open()

        End With
        sqlselect = "select * from mytable Where id = '" & txtuser_ID.Text & "' and Password = '" & txtpassword.Text & "'"



        Dim sqlcommand As New SqlCeCommand(sqlselect, myConnection)

        sqlreader = sqlcommand.ExecuteReader
        sqlreader.Read()
        userida = CStr(sqlreader.Item("id"))
        passida = CStr(sqlreader.Item("password"))

        If txtuser_ID.Text = userida And txtpassword.Text = passida Then
            chair.Show()
            txtuser_ID.Text = ""
            txtpassword.Text = ""
            Me.Hide()
        Else


            MessageBox.Show("กรุณาใส่ข้อมูลให้ถูกต้อง", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning)

        End If
    End Sub




Tag : .NET, VB.NET









ประวัติการแก้ไข
2012-02-25 20:05:16
2012-02-25 20:05:52
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-02-25 20:03:30 By : Mikkola View : 1892 Reply : 11
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Debug ค่า sqlselect ให้ดูค่าหน่อยครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-25 20:23:42 By : webmaster
 


 

No. 2



โพสกระทู้ ( 249 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

Code (VB.NET)
Private Sub OK_Click(.....
If txtuser_ID.Text = "" And txtpassword.Text = "" Then
MessageBox.Show("ใส่ข้อมูล", "No userID", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
If ReadMyData(txtuser_id.text,txtpassword.text) = false then
Messagebox.Show("Username And Password ไม่ถูกต้อง")
end if
end if 

end sub


Private function ReadMyData (ByVal userid As String,ByVal password As String) as boolean
if Cnn.State = ConnectionState.Open then Cnn.Close()
Cnn.connectionstring = Cnnstring
Cnn.Open()

sqlselect = "select * from mytable Where id = '" & userid  & "' and Password = '" & password   & "'"
Dim da  as New SqlDataadapter(sqlselect,Cnn)
dim ds as New Dataset

da.fill(ds,"dtLogin")

if ds.rows.count = 0 then
return false
end if 

return true
end function

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-25 20:30:48 By : tee
 

 

No. 3



โพสกระทู้ ( 23 )
บทความ ( 0 )



สถานะออฟไลน์


Error ตามนี้เลยครับ

ปล. ลองโค้ดของพี่ tee ดู มันติดตรงบันทัดที่ 24 บอกว่า ไม่สามารถใช้ rows กับ dataset ได้

ตามนี้เลยครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-25 21:03:22 By : Mikkola
 


 

No. 4



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

มันบอกว่าไม่มี Rows และ Column ครับ

ลองใช้

Code (VB.NET)
if sqlreader.HasRows Then

Else

End IF


ผมถึงให้คุณ Debug เอาค่า SQL ออกมาดูครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-25 21:06:44 By : webmaster
 


 

No. 5



โพสกระทู้ ( 23 )
บทความ ( 0 )



สถานะออฟไลน์


จะ Debug SQL ออกมาดูยังไงเหรอครับ ผมไม่เป็นอ่ะครับ ขอโทษด้วยครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-25 21:31:26 By : Mikkola
 


 

No. 6

Guest


เอาแบบง่ายๆคือ ย้ายบรรทัดที 56 เเละ 57 ไปไว้ใน if หลังบรรทัดที่ 59

Code (VB.NET)
 Imports System.Data
Imports System.Data.SqlServerCe





Public Class Login
    Dim Cnn As New SqlCeConnection(Cnnstring)
    Dim Cnnstring As String
    Dim sqlselect As String
    Dim sqlreader As SqlCeDataReader
    Dim userida As String
    Dim passida As String
    Dim myConnection As SqlCeConnection = New SqlCeConnection("Data source=D:\Project New\WindowsApplication1\WindowsApplication1\Database1.sdf;")
    Dim myCommand As SqlCeCommand
    Dim myConn As SqlCeCommand
    Dim cmdString As String


    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click

        
        With Cnn
            If .State = ConnectionState.Open Then Close()
            .ConnectionString = Cnnstring
            myConnection.Open()
            myConnection.Close()
        End With
        If txtuser_ID.Text = "" And txtpassword.Text = "" Then
            MessageBox.Show("ใส่ข้อมูล", "No userID", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Else
            ReadMyData(Cnnstring)
        End If


    End Sub

   
    Public Sub readmydata(ByVal myConnString As String)
        On Error GoTo 0
        With Cnn
            If .State = ConnectionState.Open Then Close()
            .ConnectionString = Cnnstring
            myConnection.Open()

        End With
        sqlselect = "select * from mytable Where id = '" & txtuser_ID.Text & "' and Password = '" & txtpassword.Text & "'"



        Dim sqlcommand As New SqlCeCommand(sqlselect, myConnection)

        sqlreader = sqlcommand.ExecuteReader
        sqlreader.Read()
       if sqlreader.HasRows Then

        userida = CStr(sqlreader.Item("id"))
        passida = CStr(sqlreader.Item("password"))
end if

        If txtuser_ID.Text = userida And txtpassword.Text = passida Then
            chair.Show()
            txtuser_ID.Text = ""
            txtpassword.Text = ""
            Me.Hide()
        Else


            MessageBox.Show("กรุณาใส่ข้อมูลให้ถูกต้อง", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning)

        End If
    End Sub


เหตุผลที่มัน Error คือมัน Reader มาเป็นตารางเปล่า
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-26 04:49:14 By : noom
 


 

No. 7

Guest


เม้นข้างบนตอบผิดนะครับ ขอตอบใหม่
Code (VB.NET)
 Imports System.Data
Imports System.Data.SqlServerCe





Public Class Login
    Dim Cnn As New SqlCeConnection(Cnnstring)
    Dim Cnnstring As String
    Dim sqlselect As String
    Dim sqlreader As SqlCeDataReader
    Dim userida As String
    Dim passida As String
    Dim myConnection As SqlCeConnection = New SqlCeConnection("Data source=D:\Project New\WindowsApplication1\WindowsApplication1\Database1.sdf;")
    Dim myCommand As SqlCeCommand
    Dim myConn As SqlCeCommand
    Dim cmdString As String


    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click

        
        With Cnn
            If .State = ConnectionState.Open Then Close()
            .ConnectionString = Cnnstring
            myConnection.Open()
            myConnection.Close()
        End With
        If txtuser_ID.Text = "" And txtpassword.Text = "" Then
            MessageBox.Show("ใส่ข้อมูล", "No userID", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Else
            ReadMyData(Cnnstring)
        End If


    End Sub

   
    Public Sub readmydata(ByVal myConnString As String)
        On Error GoTo 0
        With Cnn
            If .State = ConnectionState.Open Then Close()
            .ConnectionString = Cnnstring
            myConnection.Open()

        End With
        sqlselect = "select * from mytable Where id = '" & txtuser_ID.Text & "' and Password = '" & txtpassword.Text & "'"



        Dim sqlcommand As New SqlCeCommand(sqlselect, myConnection)

        sqlreader = sqlcommand.ExecuteReader
        sqlreader.Read()

       If sqlreader.HasRows Then

                userida = CStr(sqlreader.Item("id"))
                passida = CStr(sqlreader.Item("password"))
       End If
        If txtuser_ID.Text = userida And txtpassword.Text = passida Then
            chair.Show()
            txtuser_ID.Text = ""
            txtpassword.Text = ""
            Me.Hide()
        Else


            MessageBox.Show("กรุณาใส่ข้อมูลให้ถูกต้อง", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning)

        End If
    End Sub


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-26 04:51:03 By : noom
 


 

No. 8



โพสกระทู้ ( 23 )
บทความ ( 0 )



สถานะออฟไลน์


ใช้ hasrows ไม่ได้อะครับ

ไม่ได้อะครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-26 10:08:16 By : Mikkola
 


 

No. 9



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ตัวอย่างการใช้ DataReader กับ HasRows ครับ

Code (VB.NET)
    Sub myDataReader()
        Dim strSQL As String
        Dim dtReader As SqlDataReader
        strSQL = "SELECT * FROM customer "
        dtReader = clsDB.QueryDataReader(strSQL)

        '*** Bind Rows ***'
        If dtReader.HasRows = True Then
            Me.lblCustomerID.Text = dtReader.Item("CustomerID")
            Me.lblName.Text = dtReader.Item("Name")
            Me.lblEmail.Text = dtReader.Item("Email")
            Me.lblCountryCode.Text = dtReader.Item("CountryCode")
            Me.lblBudget.Text = dtReader.Item("Budget")
            Me.lblUsed.Text = dtReader.Item("Used")
        End If
        clsDB.Close()
    End Sub

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-26 10:13:33 By : webmaster
 


 

No. 10



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ลองดูตัวอย่างพวกนี้ครับ



Go to : ขอ code Login .NET ที่ใช้กับ Windows Application ไปเช็คกับฐานข้อมูล (Ms Access 2000)
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-26 10:21:44 By : webmaster
 


 

No. 11



โพสกระทู้ ( 23 )
บทความ ( 0 )



สถานะออฟไลน์


จะลองดูครับ ขอบคุณครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-26 10:25:32 By : Mikkola
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : VB.NET ดูโค้ดหน้า Login ให้หน่อยครับ รันไม่ผ่านเวลาใส่รหัสหรือ ไอดีผิดครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่