Insert Data into a table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lawrence 007
    New Member
    • Nov 2006
    • 41

    Insert Data into a table

    Hi,

    I am pretty new to HTML programming and I am stuck in one location at the moment. I created a web page where users can enter information and add it to a table in my SQL database. I am running into a problem where my table does not allow the insert of null rows and I don't know how to create the insert statement to skip the text boxes that does not have any information in them.

    Can someone please help me?

    Lawrence
  • AricC
    Recognized Expert Top Contributor
    • Oct 2006
    • 1885

    #2
    What is your table code? Are you using 'NOT NULL' when you create the table?

    Comment

    • Lawrence 007
      New Member
      • Nov 2006
      • 41

      #3
      AricC,

      These tables were already created and all I am doing is picking up from a previous programmer to try and make it easier to insert data into the table. I don't want to change the table settings, because there are still some programs that rely on that table.

      If you want I can insert what I have done so far and you can let me know what I am doing wrong.

      Thanks Aric

      Comment

      • willakawill
        Top Contributor
        • Oct 2006
        • 1646

        #4
        Originally posted by Lawrence 007
        AricC,

        These tables were already created and all I am doing is picking up from a previous programmer to try and make it easier to insert data into the table. I don't want to change the table settings, because there are still some programs that rely on that table.

        If you want I can insert what I have done so far and you can let me know what I am doing wrong.

        Thanks Aric
        Hi Aric. Inserting what you have so far will be a great help. It may be that you just plan your insert to put 'N/A' into the fields that you have no data for.

        Comment

        • Lawrence 007
          New Member
          • Nov 2006
          • 41

          #5
          Ok,

          This is what I have at the moment:

          SQL query:

          INSERT INTO PSD (CustomerId, CheckNumber, ItemId, FrankingCharge, ServiceCharge, Name, AccountYear, LastModified, DateCreated, ServiceYear, FrankingYear, ItemPrice, Quantity, CheckTotal) VALUES (@CustomerID, @CheckNumber, @ItemID, CAST(@FrankingC harge AS Money), CAST(@ServiceCh arge AS Money), @Name, @AccountYear, @LastModified, @DateCreated, @ServiceYear, @FrankingYear, CAST(@ItemPrice AS Money), @Quantity, CAST(@CheckTota l AS Money))


          On my HTML page I have a Dropdown list that lists my customers. I also have a table where they can enter information. At this stage it is a one line table which I want to make multiple lines. This is where I am stuck at the moment, because I can't enter Null's into the table and I need to figure out how to skip the text boxes or rows in the table that do not have any information in them.

          Here is the HTML code:

          Private Sub InsertRecord(By Val sender As System.Object, ByVal e As System.EventArg s)
          Insert.Insert()

          End Sub

          </script>
          <html xmlns="http://www.w3.org/1999/xhtml" >
          <head runat="server">
          <title>Untitl ed Page</title>
          <script language="javas cript" type="text/javascript">
          <!--

          function TABLE1_onclick( ) {

          }

          // -->
          </script>
          </head>
          <body>
          <form id="form1" runat="server">
          <div align="center">
          &nbsp;<asp:SqlD ataSource ID="Insert" runat="server" ConnectionStrin g="<%$ ConnectionStrin gs:InsertConnec tion %>"
          InsertCommand=" INSERT INTO PSD (CustomerId, CheckNumber, ItemId, FrankingCharge, ServiceCharge, Name, AccountYear, LastModified, DateCreated, ServiceYear, FrankingYear, ItemPrice, Quantity, CheckTotal) VALUES (@CustomerID, @CheckNumber, @ItemID, CAST(@FrankingC harge AS Money), CAST(@ServiceCh arge AS Money), @Name, @AccountYear, @LastModified, @DateCreated, @ServiceYear, @FrankingYear, CAST(@ItemPrice AS Money), @Quantity, CAST(@CheckTota l AS Money))"
          SelectCommand=" SELECT PSD.* FROM [user].PSD"
          UpdateCommand=" UPDATE PSD SET CustomerId = @CustomerID, CheckNumber = @CheckNumber, ItemId = @ItemID, FrankingCharge = Convert(Money, @FrankingCharge ), ServiceCharge = Convert(Money, @ServiceCharge) , Name = @Name, AccountYear = @AccountYear, LastModified = @LastModified, DateCreated = @DateCreated, ServiceYear = @ServiceYear, FrankingYear = @FrankingYear, ItemPrice = Convert(Money, @ItemPrice), Quantity = @Quantity">
          <UpdateParamete rs>
          <asp:Paramete r Name="CustomerI D" />
          <asp:Paramete r Name="CheckNumb er" />
          <asp:Paramete r Name="ItemID" />
          <asp:Paramete r Name="FrankingC harge" />
          <asp:Paramete r Name="ServiceCh arge" />
          <asp:Paramete r Name="Name" />
          <asp:Paramete r Name="AccountYe ar" />
          <asp:Paramete r Name="LastModif ied" />
          <asp:Paramete r Name="DateCreat ed" />
          <asp:Paramete r Name="ServiceYe ar" />
          <asp:Paramete r Name="FrankingY ear" />
          <asp:Paramete r Name="ItemPrice " />
          <asp:Paramete r Name="Quantity" />
          </UpdateParameter s>
          <InsertParamete rs>
          <asp:ControlPar ameter ControlID="Drop DownList1" Name="CustomerI D" PropertyName="S electedValue" />
          <asp:FormParame ter Name="CheckNumb er" formfield="Chec kNumber"/>
          <asp:FormParame ter Name="ItemID" formfield="Item Dropdown"/>
          <asp:FormParame ter Name="FrankingC harge" Formfield="Fran kingBox"/>
          <asp:FormParame ter Name="ServiceCh arge" formfield="Serv iceBox"/>
          <asp:FormParame ter Name="Name" formfield="CNam eBox"/>
          <asp:FormParame ter Name="AccountYe ar" FormField="Acco untBox" />
          <asp:ControlPar ameter ControlID="Time Label" Name="LastModif ied" PropertyName="T ext" />
          <asp:ControlPar ameter ControlID="Time Label" Name="DateCreat ed" PropertyName="T ext" />
          <asp:FormParame ter Name="ServiceYe ar" FormField="Syea rBox"/>
          <asp:FormParame ter Name="FrankingY ear" FormField="Fyea rBox"/>
          <asp:FormParame ter Name="ItemPrice " FormField="Item PBox"/>
          <asp:FormParame ter Name="Quantity" FormField="QBox "/>
          <asp:FormParame ter Name="CheckTota l" FormField="CTot alBox"/>

          </InsertParameter s>
          </asp:SqlDataSour ce>

          I would greatly appreciate the help.

          Thanks a bunch!!

          Comment

          • Lawrence 007
            New Member
            • Nov 2006
            • 41

            #6
            I did not add the button Click:

            <br />
            <asp:Button
            ID="Button1"
            runat="server"
            Text="Insert Record"
            Width="181px"
            onclick="Insert Record"
            /><br />

            Thanks

            Comment

            Working...