0

ms accessデータベースに日付を保存するフォームがあるので、誰でも助けてくれますか。保存ボタンをクリックすると、データが正しく保存されることがありますが、「オーバーフロー」「ExecuteNonQuery」が宣言されていないというエラーが表示されることがあります。保護レベルにより、アクセスできない場合があります。 私はこのコードを使用しています:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If MsgBox("Are you sure you want to Add Data?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "WARNING") = MsgBoxResult.Yes Then
        Dim OleDBC As New OleDbCommand
        With OleDBC

            .Connection = conn
            .CommandText = "Insert Into tblmaritlistBA_I (form_number,name_of_candidate,fathers_name,mothers_name,category,minority,date_of_birth,gender,mobile,address,board,passed_year,intermediate_marks_obtained,intermediate_total_marks,percentage,normalization_factor,total_percentage)  VALUES ('" & txtformnumber.Text & "','" & txtstuname.Text & "','" & txtfathname.Text & "','" & txtmothname.Text & "','" & cmbcategory.Text & "','" & cmbminority.Text & "','" & dobPicker1.Text & "','" & cmbgender.Text & "','" & txtmobile.Text & "','" & txtaddress.Text & "','" & cmbboard.Text & "','" & cmbpassedyear.Text & "','" & txtintermarks.Text & "','" & txtintertotalmarks.Text & "','" & txtpercentage.Text & "','" & Lblnormalization.Text & "','" & txtpercentageafterN.Text & "')"
            .ExecuteNonQuery()
        End With
        MsgBox("Data Added!", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "SUCCESS")
        Me.Hide()

        Call initgrid()
    End If
End Sub 

助けてください("_")

4

1 に答える 1

1

コードによると、データベース接続を開いたことはありません。

connオブジェクトの接続に設定しましたが、Command最初にインスタンス化したり、開いたりしませんでした。

以下のコードを参照してください。オブジェクトが作成され(Connection独自の接続文字列を挿入)、開かれます。

エラーが発生した場合でも接続を閉じるために、最後にその接続をFinallyブロックで閉じる必要があります

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

    Dim conn As OleDbConnection
    Try
        If MsgBox("Are you sure you want to Add Data?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "WARNING") = MsgBoxResult.Yes Then

            conn = New OleDbConnection("YOUR_CONNECTIONSTRING_HERE")
            conn.Open()

            Dim OleDBC As New OleDbCommand

            With OleDBC
                .Connection = conn
                .CommandText = "Insert Into tblmaritlistBA_I (form_number,name_of_candidate,fathers_name,mothers_name,category,minority,date_of_birth,gender,mobile,address,board,passed_year,intermediate_marks_obtained,intermediate_total_marks,percentage,normalization_factor,total_percentage)  VALUES ('" & txtformnumber.Text & "','" & txtstuname.Text & "','" & txtfathname.Text & "','" & txtmothname.Text & "','" & cmbcategory.Text & "','" & cmbminority.Text & "','" & dobPicker1.Text & "','" & cmbgender.Text & "','" & txtmobile.Text & "','" & txtaddress.Text & "','" & cmbboard.Text & "','" & cmbpassedyear.Text & "','" & txtintermarks.Text & "','" & txtintertotalmarks.Text & "','" & txtpercentage.Text & "','" & Lblnormalization.Text & "','" & txtpercentageafterN.Text & "')"
                .ExecuteNonQuery()
            End With

            MsgBox("Data Added!", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "SUCCESS")
            Me.Hide()

            Call initgrid()
        End If

    Catch ex As Exception
        MsgBox("Error : " & ex.ToString)
    Finally
        If (conn.state and ConnectionState.Open) <>0 Then 
            conn.Close 
        End If
    End Try

End Sub
于 2012-05-31T03:23:42.750 に答える