0

ここで少し苦労します。本の記録の形で、ユーザー入力を私のデータベースにリンクするコードを開発しようとしています。たとえば、ユーザーは自分の名前アドレスなどを入力するように求められます。しかし、同じエラーが継続的に発生するため、使用したコードは実行されないようです。

Line 12:         Dim con As New SqlConnection
Line 13:         Dim inscmd As New SqlCommand
Line 14:         con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("Database.My.MySettings.Database1ConnectionString1").ConnectionString
Line 15:         con.Open()
Line 16:         inscmd.CommandText = ("insert into booking values('" + txtfirstname.Text + "', " + txtSurname.Text + "', " + txtAddressline1.Text + "', " + txtAddressline2.Text + "', " + txtPostcode.Text + "', " + txtTime.Text + "', " + txtPeople.Text + "', " + txtDropoff1.Text + "', " + txtDropoff2.Text + "', " + txtDropoffpost.Text + "")

エラーが含まれているのは14行目ですが、理由はわかりません。これは私のコードです。

Protected Sub btnsubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles  btnsubmit.Click
    Dim con As New SqlConnection
    Dim inscmd As New SqlCommand
    con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("Database.My.MySettings.Database1ConnectionString1").ConnectionString
    con.Open()
    inscmd.CommandText = ("insert into booking values('" + txtfirstname.Text + "', " + txtSurname.Text + "', " + txtAddressline1.Text + "', " + txtAddressline2.Text + "', " + txtPostcode.Text + "', " + txtTime.Text + "', " + txtPeople.Text + "', " + txtDropoff1.Text + "', " + txtDropoff2.Text + "', " + txtDropoffpost.Text + "")
    Print(inscmd.CommandText)
    inscmd.Connection = con
    inscmd.ExecuteNonQuery()
    con.Close()
    inscmd.Parameters.Clear()

    MsgBox("Your booking has been successfully")
    con.Close()

End Sub
4

4 に答える 4

0
insert into booking values('" + txtfirstname.Text + "', " + txtSurname.Text + "', " + txtAddressline1.Text + "', " + txtAddressline2.Text + "', " + txtPostcode.Text + "', " + txtTime.Text + "', " + txtPeople.Text + "', " + txtDropoff1.Text + "', " + txtDropoff2.Text + "', " + txtDropoffpost.Text + "

する必要があります

insert into booking values('" + txtfirstname.Text + "', '" + txtSurname.Text + "', '" + txtAddressline1.Text + "', '" + txtAddressline2.Text + "', '" + txtPostcode.Text + "', " + txtTime.Text + "', '" + txtPeople.Text + "', '" + txtDropoff1.Text + "', '" + txtDropoff2.Text + "', '" + txtDropoffpost.Text + "')"
于 2013-04-29T13:16:46.100 に答える
0

[プロジェクト設定] ウィンドウで接続文字列ウィザードを使用する必要があります。次に、テスト接続ボタンを試してください。設定のタイプが ConnectionString であることを確認してください。正しく設定されていれば、この構文を使用して接続文字列を取得できるはずです。

con.ConnectionString = my.Settings.Database1ConnectionString1
于 2013-04-29T13:53:39.640 に答える
0
strSQL = "INSERT INTO user_account_details" & _
                "(lastname,firstname,middlename,usertype,reg_date_time,status)" & _
                " VALUES ( " & _
                " '" & txtLName.Text & "', " & _
                " '" & txtFName.Text & "' , " & _
                " '" & txtMName.Text & "' , " & _
                " '" & cboUserType.Text & "' , " & _
                " '#" & Now & "#', " & _
                " 'Inactive' " & _
                ")"
于 2017-02-12T15:00:22.840 に答える