本文介绍了我试图插入信息到两个表上的单个btnclick。其写入只有一个表依然。不能看我缺少什么。任何人都可以帮忙吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 保护小组的Page_Load(BYVAL发件人为对象,BYVAL E上System.EventArgs)    如果(不Page.IsPostBack)然后
        昏暗strDatabaseNameAndLocation作为字符串
        strDatabaseNameAndLocation =使用Server.Mappath(databob.mdb)
        昏暗strSQLCommand作为字符串
        strSQLCommand =SELECT *的客户来自客户的ORDER BY Customers.CustomerID DESC。
        昏暗objOleDbConnection作为System.Data.OleDb.OleDbConnection
        objOleDbConnection =新System.Data.OleDb.OleDbConnection(提供者= Microsoft.Jet.Oledb.4.0;数据源=&放大器; strDatabaseNameAndLocation)
        objOleDbConnection.Open()
        昏暗objOleDbCommand作为System.Data.OleDb.OleDbCommand
        objOleDbCommand =新System.Data.OleDb.OleDbCommand(strSQLCommand,objOleDbConnection)
        昏暗objOleDbDataReader作为System.Data.OleDb.OleDbDataReader
        objOleDbDataReader = objOleDbCommand.ExecuteReader()
        昏暗datDataTable作为System.Data.DataTable
        datDataTable =新System.Data.DataTable()
        datDataTable.Load(objOleDbDataReader)
        objOleDbConnection.Close()
    万一
    如果(不Page.IsPostBack)然后
        昏暗strDatabaseNameAndLocation作为字符串
        strDatabaseNameAndLocation =使用Server.Mappath(databob.mdb)
        昏暗strSQLCommand2作为字符串
        strSQLCommand2 =SELECT CardType,CardNumber,有效,过期,3Digit从接单ORDER BY Orders.OrderID DESC;
        昏暗objOleDbConnection作为System.Data.OleDb.OleDbConnection
        objOleDbConnection =新System.Data.OleDb.OleDbConnection(提供者= Microsoft.Jet.Oledb.4.0;数据源=&放大器; strDatabaseNameAndLocation)
        objOleDbConnection.Open()
        昏暗objOleDbCommand作为System.Data.OleDb.OleDbCommand
        objOleDbCommand =新System.Data.OleDb.OleDbCommand(strSQLCommand2,objOleDbConnection)
        昏暗objOleDbDataReader作为System.Data.OleDb.OleDbDataReader
        objOleDbDataReader = objOleDbCommand.ExecuteReader()
        昏暗datDataTable作为System.Data.DataTable
        datDataTable =新System.Data.DataTable()
        datDataTable.Load(objOleDbDataReader)
        objOleDbConnection.Close()
    万一结束小组保护小组btnContinue_Click(BYVAL发件人为对象,BYVAL E上System.EventArgs)    昏暗strFirstName作为字符串
    昏暗strLastName作为字符串
    昏暗strAddress作为字符串
    昏暗的strPost code作为字符串
    昏暗strHomeNo作为字符串
    昏暗strMobileNo作为字符串
    昏暗strEmail作为字符串
    昏暗strCardType作为字符串
    昏暗strCardNumber作为字符串
    昏暗strValid作为字符串
    昏暗strExpiry作为字符串
    昏暗str3Digit作为字符串
    strFirstName = tbxFirstName.Text
    strLastName = tbxLastName.Text
    strAddress = tbxAddress.Text
    strPost code = tbxPost code.Text
    strHomeNo = tbxHomeNo.Text
    strMobileNo = tbxMobileNo.Text
    strEmail = tbxEmail.Text
    strCardType = ddlCardType.Text
    strCardNumber = tbxCardNumber.Text
    strValid = tbxValid.Text
    strExpiry = tbxExpiry.Text
    str3Digit = tbx3Digit.Text    昏暗strDatabaseNameAndLocation作为字符串
    strDatabaseNameAndLocation =使用Server.Mappath(databob.mdb)
    昏暗strSQLCommand作为字符串
    strSQLCommand =INSERT INTO客户(名字,姓氏,地址,邮报code,HomeNo,MobileNo,电子邮件)与& _
    VALUES('&放大器; strFirstName&安培;','&放大器; strLastName&安培;','&放大器; strAddress&安培;','&放大器; strPost code&放,','&放大器; strHomeNo&安培;','&放大器; strMobileNo&安培;','&放大器; strEmail&安培;');
    昏暗strSQLCommand2作为字符串
    strSQLCommand2 =INSERT INTO订单(CardType,CardNumber,有效,过期,3Digit)&放大器; _
        VALUES('&放大器; strCardType&安培;','&放大器; strCardNumber&安培;','&放大器; strValid&安培;','&放大器; strExpiry&安培;','&放大器; str3Digit&安培; ');
    昏暗objOleDbConnection作为System.Data.OleDb.OleDbConnection
    objOleDbConnection =新System.Data.OleDb.OleDbConnection(提供者= Microsoft.Jet.Oledb.4.0;数据源=&放大器; strDatabaseNameAndLocation)
    objOleDbConnection.Open()
    昏暗objOleDbCommand作为System.Data.OleDb.OleDbCommand
    objOleDbCommand =新System.Data.OleDb.OleDbCommand(strSQLCommand,objOleDbConnection)
    objOleDbCommand.ExecuteNonQuery()
    objOleDbConnection.Close()
    strSQLCommand =SELECT *的客户来自客户的ORDER BY Customers.CustomerID DESC。
    strSQLCommand2 =SELECT *订单从接单ORDER BY Orders.OrderID DESC。
    objOleDbConnection =新System.Data.OleDb.OleDbConnection(提供者= Microsoft.Jet.Oledb.4.0;数据源=&放大器; strDatabaseNameAndLocation)
    objOleDbConnection.Open()
    objOleDbCommand =新System.Data.OleDb.OleDbCommand(strSQLCommand,objOleDbConnection)
    昏暗objOleDbDataReader作为System.Data.OleDb.OleDbDataReader
    objOleDbDataReader = objOleDbCommand.ExecuteReader()
    昏暗datDataTable作为System.Data.DataTable
    datDataTable =新System.Data.DataTable()
    datDataTable.Load(objOleDbDataReader)
    objOleDbConnection.Close()
    tbxFirstName.Text =
    tbxLastName.Text =
    tbxAddress.Text =
    tbxPost code.Text =
    tbxHomeNo.Text =
    tbxMobileNo.Text =
    tbxEmail.Text =
    ddlCardType.Text =
    tbxCardNumber.Text =
    tbxValid.Text =
    tbxExpiry.Text =
    tbx3Digit.Text =结束小组


解决方案

INSERT INTO订单(订单(看起来腥稍微给我(除非这是一个C&放大器,P错误张贴这个问题)


和肯所指出的,如果你想运行这两个查询(而不是更换一个与其他),你可能想:

  strSQLCommand = strSQLCommand&安培; INSERT INTO订单(CardType,CardNumber,有效,过期,3Digit)&放大器; _
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

    If (Not Page.IsPostBack) Then
        Dim strDatabaseNameAndLocation As String
        strDatabaseNameAndLocation = Server.MapPath("databob.mdb")
        Dim strSQLCommand As String
        strSQLCommand = "SELECT Customers.* FROM Customers ORDER BY Customers.CustomerID DESC;"
        Dim objOleDbConnection As System.Data.OleDb.OleDbConnection
        objOleDbConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & strDatabaseNameAndLocation)
        objOleDbConnection.Open()
        Dim objOleDbCommand As System.Data.OleDb.OleDbCommand
        objOleDbCommand = New System.Data.OleDb.OleDbCommand(strSQLCommand, objOleDbConnection)
        Dim objOleDbDataReader As System.Data.OleDb.OleDbDataReader
        objOleDbDataReader = objOleDbCommand.ExecuteReader()
        Dim datDataTable As System.Data.DataTable
        datDataTable = New System.Data.DataTable()
        datDataTable.Load(objOleDbDataReader)
        objOleDbConnection.Close()
    End If


    If (Not Page.IsPostBack) Then
        Dim strDatabaseNameAndLocation As String
        strDatabaseNameAndLocation = Server.MapPath("databob.mdb")
        Dim strSQLCommand2 As String
        strSQLCommand2 = "SELECT CardType, CardNumber, Valid, Expiry, 3Digit FROM Orders ORDER BY Orders.OrderID DESC;"
        Dim objOleDbConnection As System.Data.OleDb.OleDbConnection
        objOleDbConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & strDatabaseNameAndLocation)
        objOleDbConnection.Open()
        Dim objOleDbCommand As System.Data.OleDb.OleDbCommand
        objOleDbCommand = New System.Data.OleDb.OleDbCommand(strSQLCommand2, objOleDbConnection)
        Dim objOleDbDataReader As System.Data.OleDb.OleDbDataReader
        objOleDbDataReader = objOleDbCommand.ExecuteReader()
        Dim datDataTable As System.Data.DataTable
        datDataTable = New System.Data.DataTable()
        datDataTable.Load(objOleDbDataReader)
        objOleDbConnection.Close()
    End If

End Sub

Protected Sub btnContinue_Click(ByVal sender As Object, ByVal e As System.EventArgs)

    Dim strFirstName As String
    Dim strLastName As String
    Dim strAddress As String
    Dim strPostcode As String
    Dim strHomeNo As String
    Dim strMobileNo As String
    Dim strEmail As String
    Dim strCardType As String
    Dim strCardNumber As String
    Dim strValid As String
    Dim strExpiry As String
    Dim str3Digit As String
    strFirstName = tbxFirstName.Text
    strLastName = tbxLastName.Text
    strAddress = tbxAddress.Text
    strPostcode = tbxPostcode.Text
    strHomeNo = tbxHomeNo.Text
    strMobileNo = tbxMobileNo.Text
    strEmail = tbxEmail.Text
    strCardType = ddlCardType.Text
    strCardNumber = tbxCardNumber.Text
    strValid = tbxValid.Text
    strExpiry = tbxExpiry.Text
    str3Digit = tbx3Digit.Text

    Dim strDatabaseNameAndLocation As String
    strDatabaseNameAndLocation = Server.MapPath("databob.mdb")
    Dim strSQLCommand As String
    strSQLCommand = "INSERT INTO Customers(FirstName, LastName, Address, Postcode, HomeNo, MobileNo, Email) " & _
    "Values ('" & strFirstName & "', '" & strLastName & "', '" & strAddress & "', '" & strPostcode & "', '" & strHomeNo & "', '" & strMobileNo & "', '" & strEmail & "');"
    Dim strSQLCommand2 As String
    strSQLCommand2 = "INSERT INTO Orders(CardType, CardNumber, Valid, Expiry, 3Digit) " & _
        "Values ('" & strCardType & "', '" & strCardNumber & "', '" & strValid & "', '" & strExpiry & "', '" & str3Digit & "');"
    Dim objOleDbConnection As System.Data.OleDb.OleDbConnection
    objOleDbConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & strDatabaseNameAndLocation)
    objOleDbConnection.Open()
    Dim objOleDbCommand As System.Data.OleDb.OleDbCommand
    objOleDbCommand = New System.Data.OleDb.OleDbCommand(strSQLCommand, objOleDbConnection)
    objOleDbCommand.ExecuteNonQuery()
    objOleDbConnection.Close()
    strSQLCommand = "SELECT Customers.* FROM Customers ORDER BY Customers.CustomerID DESC;"
    strSQLCommand2 = "SELECT Orders.* FROM Orders ORDER BY Orders.OrderID DESC;"
    objOleDbConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & strDatabaseNameAndLocation)
    objOleDbConnection.Open()
    objOleDbCommand = New System.Data.OleDb.OleDbCommand(strSQLCommand, objOleDbConnection)
    Dim objOleDbDataReader As System.Data.OleDb.OleDbDataReader
    objOleDbDataReader = objOleDbCommand.ExecuteReader()
    Dim datDataTable As System.Data.DataTable
    datDataTable = New System.Data.DataTable()
    datDataTable.Load(objOleDbDataReader)
    objOleDbConnection.Close()
    tbxFirstName.Text = ""
    tbxLastName.Text = ""
    tbxAddress.Text = ""
    tbxPostcode.Text = ""
    tbxHomeNo.Text = ""
    tbxMobileNo.Text = ""
    tbxEmail.Text = ""
    ddlCardType.Text = ""
    tbxCardNumber.Text = ""
    tbxValid.Text = ""
    tbxExpiry.Text = ""
    tbx3Digit.Text = ""



End Sub
解决方案

INSERT INTO Orders(Orders( looks a tad fishy to me (unless that's a C&P error posting this question)


And as Ken points out, if you're wanting to run both queries (rather than replace one with the other), you probably want:

strSQLCommand = strSQLCommand & " INSERT INTO Orders(CardType, CardNumber, Valid, Expiry, 3Digit) " & _

这篇关于我试图插入信息到两个表上的单个btnclick。其写入只有一个表依然。不能看我缺少什么。任何人都可以帮忙吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 12:25