vb.net
  • ms-access-2010
  • vb.net-2010
  • 2016-05-22 9 views -1 likes 
    -1

    データを持つテキストボックスがあります。次に、[更新]をクリックすると、すべてのテキストボックスが有効になり、編集することができます。私は、更新をクリックすると、再び、それはあなたが警告してきたように、パラメータ化クエリを使用し、私は保存時のUPDATEステートメントのエラー

     myConnection.Open() 
        Dim str As String = "UPDATE StudentDatabase set FName='" & FNameTextBox.Text & "',MName='" & MNameTextBox.Text & "',LName='" & LNameTextBox.Text & "' ,DOB='" & DOBDateTimePicker.Text & "',Gender='" & GenderTextBox.Text & "',Address='" & AddressTextBox.Text & "',Section='" & SectionTextBox.Text & "',FatherName='" & FatherNameTextBox.Text & "',FatherOccupation='" & FatherOccupationTextBox.Text & "',FatherContact='" & FatherContactTextBox.Text & "',MotherName='" & MotherNameTextBox.Text & "',MotherOccupation='" & MotherOccupationTextBox.Text & "',MotherContact='" & MotherContactTextBox.Text & "',Guardian='" & GuardianTextBox.Text & "',GuardianContact='" & GuardianContactTextBox.Text & "' where StudID='" & StudIDTextBox.Text & "' " 
        Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection) 
        If (LNameTextBox.ReadOnly = True) Then 
         FNameTextBox.ReadOnly = False 
         LNameTextBox.ReadOnly = False 
         MNameTextBox.ReadOnly = False 
         GenderTextBox.ReadOnly = False 
         AddressTextBox.ReadOnly = False 
         SectionTextBox.ReadOnly = False 
         FatherNameTextBox.ReadOnly = False 
         FatherContactTextBox.ReadOnly = False 
         FatherOccupationTextBox.ReadOnly = False 
         MotherNameTextBox.ReadOnly = False 
         MotherContactTextBox.ReadOnly = False 
         MotherOccupationTextBox.ReadOnly = False 
         GuardianContactTextBox.ReadOnly = False 
         GuardianTextBox.ReadOnly = False 
        ElseIf (LNameTextBox.ReadOnly = False) Then 
    
         Try 
    
    
          cmd.ExecuteNonQuery() 
    
    
          FNameTextBox.ReadOnly = True 
          LNameTextBox.ReadOnly = True 
          MNameTextBox.ReadOnly = True 
          GenderTextBox.ReadOnly = True 
          AddressTextBox.ReadOnly = True 
          SectionTextBox.ReadOnly = True 
          FatherNameTextBox.ReadOnly = True 
          FatherContactTextBox.ReadOnly = True 
          FatherOccupationTextBox.ReadOnly = True 
          MotherNameTextBox.ReadOnly = True 
          MotherContactTextBox.ReadOnly = True 
          MotherOccupationTextBox.ReadOnly = True 
          GuardianContactTextBox.ReadOnly = True 
          GuardianTextBox.ReadOnly = True 
          myConnection.Close() 
    
         Catch ex As Exception 
          MsgBox(ex.Message) 
         End Try 
    
        End If 
    
    +0

    この更新コードを実行しているときに、テキストボックスにアポストロフィや引用符が含まれていますか?これがセットアップされる方法は、SQLインジェクションの影響を受けます。 –

    +0

    パラメータを使う...私は 'StudentDatabse'をで落とすことができました。 '; DROP StudentDatabase'フィールドの' StudIDTextBox'だけです... – Codexer

    +0

    常にパラメータ化されたクエリを使用してください。それはあなたのsytaxエラーステートメントを解決するだけでなく、SQLインジェクション攻撃からあなたを守ります。文字列=「UPDATE StudentDatabase SETします。FName = @FName、MNAME = @MName、..... "' \t \t 'Cmd.Parameters.Add(" @ fNameをしたよう '薄暗いSTR: あなたのコードは次のようになります。 "、SqlDBType.VarChar).Value = FNameTextBox.Text' \t' Cmd.Parameters.Add( "@MName、SqlDBType.VarChar).Value = MNameTextBox' \t' ... ' –

    答えて

    0

    まずは「UPDATE文で構文エラー」

    をというエラーを得続ける救うが、 ます。例外から十分な情報が得られない場合は、完全なクエリーをコンソールに書き込んで、構文を簡単に調べることを検討してください。 dobdatetimepicker.textが返す形式は、データベースが期待するものです(しかし、私が間違っていなければ別のエラーメッセージが表示されるでしょう)。それらのどれもが問題を明らかにしていない場合は、何か異なることが起こるまでクエリ文字列から入力を取り除きます。

     関連する問題

    • 関連する問題はありません^_^