Textinfo不张贴到.mdb文件.不知道为什么

本文关键字:文件 不知道 为什么 mdb 张贴 Textinfo | 更新日期: 2023-09-27 18:19:13

我目前在一个特定的问题上被难住了,我需要你的帮助。我的asp.net网站有这个特别的问题。

无论出于何种原因,当用户试图将文本框中的信息保存到我的.mdb文件时,它不接受它。一切都编译得很好,我已经四次检查了所有的ID和字符串名称,一切似乎都与.mdb, .c文件和aspx.cs页面中的表上的内容相匹配。

这里是.aspx页面,信息输入在

 <asp:Label ID="lblFirstName1" runat="server" align="left" Text="First Name: " Width="125px"></asp:Label>
        <asp:TextBox ID="txtfirstName" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
            ControlToValidate="txtfirstName" ErrorMessage="First Name cannot be empty"></asp:RequiredFieldValidator>
        <br />
        <asp:Label ID="lblLastName1" runat="server" Text="Last Name: " Width="125px"></asp:Label>
        <asp:TextBox ID="txtlastName" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
            ControlToValidate="txtlastName" ErrorMessage="Last Name cannot be empty"></asp:RequiredFieldValidator>
        <br />

         <asp:Label ID="lblUserAddress1" runat="server" Text="Street Addres: " Width="125px"></asp:Label>
         <asp:TextBox ID="txtstreetAddress" runat="server"></asp:TextBox>
         <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="txtstreetAddress"
             ErrorMessage="Address cannot be empty"></asp:RequiredFieldValidator>
         <br />
         <asp:Label ID="lblcity1" runat="server" Text="City: " Width="125px"></asp:Label>
         <asp:TextBox ID="txtcity" runat="server"></asp:TextBox>
         <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="txtcity"
             ErrorMessage="City cannot be empty"></asp:RequiredFieldValidator>
         <br />
         <asp:Label ID="lblstate1" runat="server" Text="State: " Width="125px"></asp:Label>
         <asp:TextBox ID="txtstate" runat="server"></asp:TextBox>
         <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="txtstate"
             ErrorMessage="State cannot be empty"></asp:RequiredFieldValidator>
         <br />
         <asp:Label ID="lblzipCode1" runat="server" Text="Zip Code: " Width="125px"></asp:Label>
         <asp:TextBox ID="txtzipCode" runat="server"></asp:TextBox>
         <asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ControlToValidate="txtzipCode"
             ErrorMessage="Zip Code cannot be empty"></asp:RequiredFieldValidator>

这里是来自。cs页面的信息,它用来保存到。mdb

      public static bool Saveneworder(string Database, string firstName, string lastName, string streetAddress, string city, string state, string zipCode )
{
      bool recordSaved;
    // Create a new Oledb Transaction object
    OleDbTransaction myTransaction = null;
     try
    {
        // Create a New Connection Object to the Access Database
        OleDbConnection conn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" +
        "Data Source=" + Database);
        conn.Open();
        OleDbCommand command = conn.CreateCommand();
        string strSQL;
        // set the transaction object and start the transaction
        myTransaction = conn.BeginTransaction();
        command.Transaction = myTransaction;
          strSQL = "Insert into tblOrder " +
        "(firstName, lastName, streetAddress, city, state, zipCode) values ('" +
        firstName + "', '" + lastName + "', '" + streetAddress + "', '" + city + "', '" + state +
        "', '" + zipCode + "')";
          // set the command text of the command object
          command.CommandType = CommandType.Text;
          command.CommandText = strSQL;
          // Execute the insert statement
          command.ExecuteNonQuery();
          myTransaction.Commit();
          // Close the Database connection
          conn.Close();
          recordSaved = true;
    }
     catch (Exception ex)
     {
         //Rollback the transaction if some failure occurs
         myTransaction.Rollback();
         recordSaved = false;

     }
     return recordSaved;

}

这是第一个aspx.cs文件,它将数据从文本框传输到orderverified页面,该页面列出了信息未发布的else语句

  protected void btnSubmit_Click(object sender, EventArgs e)
{
    if (ValidateFields()) //if Validate fields method has returned true
    {
         Session.Add("txtfirstName", txtfirstName.Text);
        Session.Add("txtlastName", txtlastName.Text);
        Session.Add("txtstreetAddress", txtstreetAddress.Text);
        Session.Add("txtcity", txtcity.Text);
        Session.Add("txtstate", txtstate.Text);
        Session.Add("txtzipCode", txtzipCode.Text);

        Server.Transfer("orderverified.aspx");

}

,它将信息转发到这个aspx.cs文件

  protected void Page_Load(object sender, EventArgs e)
{
    //So here we are initializing text property of the textbox "txtVerifiedInfo" after fetching the
    //values from the session object
    txtVerifiedInfo.Text =   Session["txtfirstName"].ToString() +
   "'n" + Session["txtlastName"].ToString() +
   "'n" + Session["txtstreetAddress"].ToString() +
   "'n" + Session["txtcity"].ToString() +
   "'n" + Session["txtstate"].ToString() +
   "'n" + Session["txtzipCode"].ToString() 
                                                  ;
    // Check if the record is successfully saved in the tblOrder Table and prints the appropriate message in the text box txtVerifiedInfo
    if (clsDataLayer.Saveneworder(Server.MapPath("App_Data''WSC_DB.mdb" ),
    Session["txtfirstName"].ToString(),
    Session["txtlastName"].ToString(),
    Session["txtstreetAddress"].ToString(),
    Session["txtcity"].ToString(),
    Session["txtstate"].ToString(),
    Session["txtzipCode"].ToString()  ))

    {
        txtVerifiedInfo.Text = txtVerifiedInfo.Text +
        "'nThe Order successfully submitted!";
    }
    else
    {
        txtVerifiedInfo.Text = txtVerifiedInfo.Text +
        "'n The order did not save, please return to the previous screen and verify all of your data is correct, thank you.";
    }    

在最后一页-订单验证。aspx我有一个多行文本框,清楚地显示所有的数据,但它返回我的else语句,它无法保存到tblOrder

很抱歉贴了这么多代码,但我真的很困惑为什么这不是保存。

感谢您的阅读和您的时间

在进一步的故障排除我已经尝试排除一切除了firstName和它仍然不会发布。我觉得问题是最有可能与。cs文件代码是sql语句插入到tblOrder

Textinfo不张贴到.mdb文件.不知道为什么

我从来没有使用过OleDbConnection,但似乎你可能需要使用。parameters . addwithvalue()。

好吧,我想明白了-我找不到任何代码的问题,因为没有一个!!我发现我有主键在.mdb设置为一个字段,我没有输入,它导致它不保存,因为它被设置为文本而不是自动编号,不会让文件保存!!谢谢你看了一下,jeremywho