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]
[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]
Comment