2017-04-16 8 views
-1

Mysql接続でこのエラーが発生しました。コードはパスワードを変更するためのものです。私はたくさん試しましたが、私はエラーを解決する方法がありません。助けてください。エラー1配列の境界が型指定子に表示されない

Imports MySql.Data.MySqlClient 
Imports System.Security.Cryptography 
Imports System.Text 
Imports System.Data 

Public Class frmchpwd 
    Dim myconnection As MySqlConnection(ConnectionString) 

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
     Me.Close() 
    End Sub 

    Private Sub btnProfileChangePwd_Click(sender As Object, e As EventArgs) Handles btnProfileChangePwd.Click 
     Try 
      Dim RowsAffected As Integer = 0 
      If Len(Trim(OldPassword.Text)) = 0 Then 
       MessageBox.Show("Please enter old password", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error) 
       OldPassword.Focus() 
       Exit Sub 
      End If 
      If Len(Trim(NewPassword.Text)) = 0 Then 
       MessageBox.Show("Please enter new password", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error) 
       NewPassword.Focus() 
       Exit Sub 
      End If 
      If Len(Trim(ConfirmPassword.Text)) = 0 Then 
       MessageBox.Show("Please confirm new password", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error) 
       ConfirmPassword.Focus() 
       Exit Sub 
      End If 
      If NewPassword.TextLength < 5 Then 
       MessageBox.Show("The New Password Should be of Atleast 5 Characters", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error) 
       NewPassword.Text = "" 
       ConfirmPassword.Text = "" 
       NewPassword.Focus() 
       Exit Sub 
      ElseIf NewPassword.Text <> ConfirmPassword.Text Then 
       MessageBox.Show("Password do not match", "Input error", MessageBoxButtons.OK, MessageBoxIcon.Error) 
       NewPassword.Text = "" 
       OldPassword.Text = "" 
       ConfirmPassword.Text = "" 
       OldPassword.Focus() 
       Exit Sub 
      ElseIf OldPassword.Text = NewPassword.Text Then 
       MessageBox.Show("Password is same.. Re-enter new password", "Input error", MessageBoxButtons.OK, MessageBoxIcon.Error) 
       NewPassword.Text = "" 
       ConfirmPassword.Text = "" 
       NewPassword.Focus() 
       Exit Sub 
      End If 
      If myconnection.State <> ConnectionState.Open Then 
       myconnection.Open() 
      End If 

      Dim hash, hashold As String 
      Using md5Hash As MD5 = MD5.Create() 
       hash = GetMd5Hash(md5Hash, NewPassword.Text) 
       hashold = GetMd5Hash(md5Hash, OldPassword.Text) 
      End Using 

      Dim co As String = "UPDATE logininfo_tb SET password = '" & hash & "' WHERE user_id ='" & SqlSafe(curent_user_id) & "' and password = '" & hashold & "';" 
      Dim cmd = New MySqlCommand(co) 
      cmd.Connection = myconnection 
      RowsAffected = cmd.ExecuteNonQuery() 
      If RowsAffected > 0 Then 
       NewPassword.Text = "" 
       OldPassword.Text = "" 
       ConfirmPassword.Text = "" 
       OldPassword.Focus() 
       'tracksystemlogs("Changed Password") 
       MessageBox.Show("Successfully changed", "Password", MessageBoxButtons.OK, MessageBoxIcon.Information) 
       Me.Close() 
      Else 
       MessageBox.Show("invalid email or password", "input error", MessageBoxButtons.OK, MessageBoxIcon.Error) 
       NewPassword.Text = "" 
       OldPassword.Text = "" 
       ConfirmPassword.Text = "" 
       OldPassword.Focus() 
      End If 
      If myconnection.State = ConnectionState.Open Then 
       myconnection.Close() 
      End If 
     Catch ex As Exception 
      If ex.Message.Contains("MySQL hosts") Then 
       MessageBox.Show("Server not found", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information) 
      Else 
       MessageBox.Show(ex.Message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information) 
      End If 
     End Try 
    End Sub 

    Shared Function GetMd5Hash(ByVal md5Hash As MD5, ByVal input As String) As String 
     ' Convert the input string to a byte array and compute the hash. 
     Dim data As Byte() = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input)) 

     ' Create a new Stringbuilder to collect the bytes 
     ' and create a string. 
     Dim sBuilder As New StringBuilder() 

     ' Loop through each byte of the hashed data 
     ' and format each one as a hexadecimal string. 
     Dim i As Integer 
     For i = 0 To data.Length - 1 
      sBuilder.Append(data(i).ToString("x2")) 
     Next i 

     ' Return the hexadecimal string. 
     Return sBuilder.ToString() 
    End Function 'GetMd5Hash 
End Class 
+1

このコードの壁を掲示するのではなく、問題を説明するだけの方法で投稿するのはいかがですか。 – Blackwood

答えて

0

やあみんな、私は最終的にMySqlConnectionにして、それが新しいMySqlConnectionに(のConnectionString)として

薄暗いMyConnectionとになっていた、それを解決しました。誰もがこれで祝福されることを願っています。ありがとう。

関連する問題