मैं अपने डेटाबेस के लिए Postgresql का उपयोग कर रहा हूं, मैं एक ऐप बनाना चाहता हूं जहां उपयोगकर्ता अपना खाता लॉगिन करता है, मेरे पास यह तर्क है, और मुझे यह त्रुटि मिल रही है System.NullReferenceException: 'ऑब्जेक्ट संदर्भ किसी ऑब्जेक्ट के उदाहरण पर सेट नहीं है .' मुझे यह त्रुटि क्यों मिल रही है?

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Try
            Dim Username = Username_TextBox1.Text
            Dim Password = Password_TextBox2.Text
            Dim dt As New DataTable
            Dim ds = New DataSet
            Dim i As Integer
            Try
                Using MyCon As New Odbc.OdbcConnection("Driver={PostgreSQL ANSI};database=YouthRecord;server=localhost;port=5432;uid=postgres;sslmode=disable;readonly=0;protocol=7.4;User ID=*****;password=*****;"),
                    cmd As New Odbc.OdbcCommand("SELECT * FROM YouthApp_tableuser WHERE `username` " & "='" & Username & "' and " & "password='" & Password & "'", MyCon)

                    If ds.Tables("YouthApp_tableuser").Rows.Count > 0 Then
                        For i = 0 To ds.Tables("YouthApp_tableuser").Rows.Count - 1
                            Username = ds.Tables("YouthApp_tableuser").Rows(i).Item(1).ToString
                            Password = ds.Tables("YouthApp_tableuser").Rows(i).Item(2).ToString
                        Next
                        If (Username = Username_TextBox1.Text And Password = Password_TextBox2.Text) Then
                            Username = ""
                            Password = ""

                            MainForm.Show()
                            Me.Hide()
                        Else
                            MsgBox("Invalid User! Please Enter Correct User Name and Password.", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Invalid!")
                            Username = ""
                            Password = ""
                        End If
                    End If

                    MyCon.Open()
                    dt.Load(cmd.ExecuteReader)
                End Using
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        Catch ex As Exception

        End Try

यह त्रुटि है

enter image description here

अपडेट करें

Try
   Using MyCon As New Odbc.OdbcConnection("Driver={PostgreSQL ANSI};database=YouthRecord;server=localhost;port=5432;uid=******;sslmode=disable;readonly=0;protocol=7.4;User ID=*****;password=*****;"),
   cmd As New Odbc.OdbcCommand("SELECT id, username, password FROM ""YouthApp_tableuser"" where username='" & Username & "' and password='" & Password & "' ", MyCon)
   MyCon.Open()
   dt.Load(cmd.ExecuteReader)
       If ds.Tables("YouthApp_tableuser").Rows.Count > 0 Then
             If (Username = Username_TextBox1.Text And Password = Password_TextBox2.Text) Then
                 Username = ""
                 Password = ""

                 MainForm.Show()
                 Me.Hide()
               Else
                 MsgBox("Invalid User! Please Enter Correct User Name and Password.", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Invalid!")
                  Username = ""
                  Password = ""
                End If
       End If

   End Using
Catch ex As Exception
    MessageBox.Show(ex.Message)
End Try

मुझे समान त्रुटि मिली

enter image description here

0
user12951147 26 अक्टूबर 2020, 15:32

1 उत्तर

सबसे बढ़िया उत्तर
 Try
                Using MyCon As New Odbc.OdbcConnection("Driver={PostgreSQL ANSI};database=YouthRecord;server=localhost;port=5432;uid=*****;sslmode=disable;readonly=0;protocol=7.4;User ID=*****;password=*****;"),
                    cmd As New Odbc.OdbcCommand("SELECT id, username, password FROM ""YouthApp_tableuser"" where username='" & Username & "' and password='" & Password & "' ", MyCon)
                    MyCon.Open()
                    dt.Load(cmd.ExecuteReader)

                    If dt.Rows.Count > 0 Then
                        If (Username = Username_TextBox1.Text And Password = Password_TextBox2.Text) Then
                            Username = ""
                            Password = ""

                            MainForm.Show()
                            Me.Hide()

                        End If
                    Else
                        MsgBox("Invalid User! Please Enter Correct User Name and Password.", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Invalid!")
                        Username = ""
                        Password = ""
                    End If


                End Using
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
0
kaito 26 अक्टूबर 2020, 17:11