ASP.NET- Database entry fails after 11 records

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BezerkRogue
    New Member
    • Oct 2007
    • 68

    ASP.NET- Database entry fails after 11 records

    I am using this code to enter records into a SQL DB. It fails after 11 records. Can anyone tell me what's wrong?

    [CODE=vbnet]
    Protected Sub cmdSubmit_Click (ByVal sender As Object, ByVal e As System.EventArg s) Handles cmdSubmit.Click
    'Create Date variable
    Dim d0 As Date
    d0 = occDate.Selecte dDate
    'Create frequency control
    Dim Freq2
    Freq2 = Freq.Text

    Dim objConn As New Data.SqlClient. SqlConnection(" Data Source=XXXXX;In itial Catalog=XXXXX;U ID=XXXXX;PWD=XX XXX")
    objConn.Open()
    'Create FindControl to find dynamically generated fields and converting control to text and labels so they can be directly manipulated in SQL statements
    Dim c0 As Control = Page.FindContro l("IL$ctl00$L ")
    Dim c0a As Control = Page.FindContro l("IL$Ctl00$I ")
    Dim c0b As Control = Page.FindContro l("IL$Ctl00$N ")
    Dim controlText As String = ""
    If c0 IsNot Nothing Then
    If c0.[GetType]() Is GetType(Label) Then
    Dim ca As Label = DirectCast(c0, Label)
    controlText = ca.Text
    If c0a IsNot Nothing Then
    If c0a.[GetType]() Is GetType(TextBox ) Then
    Dim cb As TextBox = DirectCast(c0a, TextBox)
    controlText = cb.Text
    If c0b IsNot Nothing Then
    If c0b.[GetType]() Is GetType(TextBox ) Then
    Dim cc As TextBox = DirectCast(c0b, TextBox)
    'SQL instructions

    Dim objCmd As New Data.SqlClient. SqlCommand("UP_ WEB_ADD_DATA_PO INT", objConn)
    objCmd.CommandT ype = Data.CommandTyp e.StoredProcedu re
    Dim IDate As New Data.SqlClient. SqlParameter("@ Date", Data.SqlDbType. DateTime)
    Dim IData As New Data.SqlClient. SqlParameter("@ Data", Data.SqlDbType. Decimal)
    Dim INotes As New Data.SqlClient. SqlParameter("@ Notes", Data.SqlDbType. VarChar)
    Dim IRepItem As New Data.SqlClient. SqlParameter("@ RepItem", Data.SqlDbType. VarChar)
    Dim IFreq As New Data.SqlClient. SqlParameter("@ Freq", Data.SqlDbType. VarChar)
    objCmd.Paramete rs.Add(IDate)
    objCmd.Paramete rs.Add(IData)
    objCmd.Paramete rs.Add(INotes)
    objCmd.Paramete rs.Add(IRepItem )
    objCmd.Paramete rs.Add(IFreq)
    IDate.Value = d0
    If cb.Text = "" Then
    IData.Value = "0"
    Else
    IData.Value = cb.Text
    End If
    INotes.Value = cc.Text
    IRepItem.Value = ca.Text
    IFreq.Value = Freq2

    objCmd.ExecuteN onQuery()
    'objConn.Close( )
    End If
    End If
    End If
    End If
    End If
    End If

    ''Coded modules repeat incrementing up to 31 controls"

    objConn.Close()
    Response.Redire ct("../RepEntered.aspx ")
    End Sub
    [/CODE]
  • Shashi Sadasivan
    Recognized Expert Top Contributor
    • Aug 2007
    • 1435

    #2
    Have you tried connecting to a database from that server. Probably the firewall must be blocking it. However whenever it fails, it should throw out an exception (if you are lucky an exception code) which will help you to track what it is all about.

    If you can paste that over here, it would be great. !

    Comment

    • BezerkRogue
      New Member
      • Oct 2007
      • 68

      #3
      The site is located on the same server as the database. The computers are accessing it from within the corporate network so there is no firewall between them. Here is the stack trace from the error message.

      [Stacktrace]
      [SqlException (0x80131904): Procedure or Function 'UP_WEB_ADD_DAT A_POINT' expects parameter '@DATA', which was not supplied.]
      System.Data.Sql Client.SqlConne ction.OnError(S qlException exception, Boolean breakConnection ) +862234
      System.Data.Sql Client.SqlInter nalConnection.O nError(SqlExcep tion exception, Boolean breakConnection ) +739110
      System.Data.Sql Client.TdsParse r.ThrowExceptio nAndWarning(Tds ParserStateObje ct stateObj) +188
      System.Data.Sql Client.TdsParse r.Run(RunBehavi or runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleR esultSet bulkCopyHandler , TdsParserStateO bject stateObj) +1956
      System.Data.Sql Client.SqlComma nd.FinishExecut eReader(SqlData Reader ds, RunBehavior runBehavior, String resetOptionsStr ing) +149
      System.Data.Sql Client.SqlComma nd.RunExecuteRe aderTds(Command Behavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +903
      System.Data.Sql Client.SqlComma nd.RunExecuteRe ader(CommandBeh avior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132
      System.Data.Sql Client.SqlComma nd.InternalExec uteNonQuery(DbA syncResult result, String methodName, Boolean sendToPipe) +415
      System.Data.Sql Client.SqlComma nd.ExecuteNonQu ery() +135
      Acct.cmdSubmit_ Click(Object sender, EventArgs e) in C:\KOI\Accounti ng\Acct.aspx.vb :561
      System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +105
      System.Web.UI.W ebControls.Butt on.RaisePostBac kEvent(String eventArgument) +107
      System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +7
      System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +11
      System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
      System.Web.UI.P age.ProcessRequ estMain(Boolean includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint) +5102
      [/Stacktrace]

      Comment

      • Shashi Sadasivan
        Recognized Expert Top Contributor
        • Aug 2007
        • 1435

        #4
        Procedure or Function 'UP_WEB_ADD_DAT A_POINT' expects parameter '@DATA', which was not supplied.]

        thats the error you need.

        The stored procedure needs that parameter, Though u have sent it across as @Data (im not sure if it is case sensitive, but a good idea to use the same case as you do in the stored procedure) it is still throwing an error.

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          I am pretty sure they ARE case sensitive, so be sure to check and correct all variables for proper casing.

          Comment

          • BezerkRogue
            New Member
            • Oct 2007
            • 68

            #6
            I have checked the file and made sure that all cases match between my code and the stored procedure. I am still getting the error. This is the code that I am getting it on:

            Code:
            If c11 IsNot Nothing Then
                        If c11.[GetType]() Is GetType(Label) Then
                            Dim ca11 As Label = DirectCast(c11, Label)
                            controlText = ca11.Text
                            If c11a.[GetType]() Is GetType(TextBox) Then
                                Dim cb11 As TextBox = DirectCast(c11a, TextBox)
                                controlText = cb11.Text
                                If c11b.[GetType]() Is GetType(TextBox) Then
                                    Dim cc11 As TextBox = DirectCast(c11b, TextBox)
                                    controlText = cc11.Text
            
                                    'SQL instructions
                                    ' Dim objConn As New Data.SqlClient.SqlConnection("Data Source=PerfDataDev;Initial Catalog=Louisville-IP;UID=master;PWD=")
                                    Dim objCmd As New Data.SqlClient.SqlCommand("UP_WEB_ADD_DATA_POINT", objConn)
                                    objCmd.CommandType = Data.CommandType.StoredProcedure
                                    Dim IDate As New Data.SqlClient.SqlParameter("@DATE", Data.SqlDbType.DateTime)
                                    Dim IData As New Data.SqlClient.SqlParameter("@DATA", Data.SqlDbType.VarChar)
                                    Dim INotes As New Data.SqlClient.SqlParameter("@NOTES", Data.SqlDbType.VarChar)
                                    Dim IRepItem As New Data.SqlClient.SqlParameter("@REPITEM", Data.SqlDbType.VarChar)
                                    Dim IFreq As New Data.SqlClient.SqlParameter("@FREQ", Data.SqlDbType.VarChar)
                                    objCmd.Parameters.Add(IDate)
                                    objCmd.Parameters.Add(INotes)
                                    objCmd.Parameters.Add(IRepItem)
                                    objCmd.Parameters.Add(IFreq)
                                    If cb11.Text = "" Then
                                        IData.Value = "0"
                                    Else
                                        IData.Value = cb11.Text
                                    End If
                                    IDate.Value = d0
                                    INotes.Value = cc11.Text
                                    IRepItem.Value = ca11.Text
                                    IFreq.Value = Freq2
                                    'objConn.Open()
                                    objCmd.ExecuteNonQuery()
                                    'objConn.Close()
                                End If
                            End If
                        End If
                    End If
            This is the same code block used for each line in the list.

            Comment

            • Shashi Sadasivan
              Recognized Expert Top Contributor
              • Aug 2007
              • 1435

              #7
              And is the exception the same now?

              Comment

              • BezerkRogue
                New Member
                • Oct 2007
                • 68

                #8
                The exception is the same. The field in the page has data so I'm not sure what is happening with it.

                Comment

                • piercy
                  New Member
                  • Aug 2007
                  • 77

                  #9
                  im not familiar with vb however, when i do parameters i do:

                  cmd.Parameters. Add("@value", SqlDataType.Tex t).Value = textBox1.Text;

                  in your code you seem to add the params before setting the values? I dont know if that would affect it but maybe set the params before (or at the same time) as adding the to the SqlCommand?

                  Hope this helps,
                  Piercy

                  Comment

                  • BezerkRogue
                    New Member
                    • Oct 2007
                    • 68

                    #10
                    This page is by far the longest that I have written. I am a newbie to coding so I tend to make many mistakes most experienced coders don't. It appears that was the case here. After going over the code for what seems like the millionth tme, I discovered that I didn't add the Data SQL parameter at all so it was never being passed. Thanks for all of your help... I have actually learned some new tricks from this.

                    Comment

                    Working...