-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
この更新コードを実行しているときに、テキストボックスにアポストロフィや引用符が含まれていますか?これがセットアップされる方法は、SQLインジェクションの影響を受けます。 –
パラメータを使う...私は 'StudentDatabse'をで落とすことができました。 '; DROP StudentDatabase'フィールドの' StudIDTextBox'だけです... – Codexer
常にパラメータ化されたクエリを使用してください。それはあなたの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' ... ' –