473,396 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

bulk insert - form collections for novice

HI There,

I am making the transition from asp to asp .net, I am currenty writing an
application that requires a bulk insert from a webform into SQL server,
normally I would just create rows of html textboxes and then use the
Request.Form.Count property to collect each field. What I would like to know
is what is a good way of doing this in asp.net? Do I need to create an array
of textboxes or can I do this fro a datagrid?
Sean - Thanks in advance
Nov 18 '05 #1
6 3159
I'm not following you 100%, but it sounds like its probably a good job for
either a datagrid or a repeater. Repeaters are more manual but give you
additional flexibility. Datagrids are more automatic but have limitations.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"Sean" <se**********@shopsmart.com.au> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
HI There,

I am making the transition from asp to asp .net, I am currenty writing an
application that requires a bulk insert from a webform into SQL server,
normally I would just create rows of html textboxes and then use the
Request.Form.Count property to collect each field. What I would like to know is what is a good way of doing this in asp.net? Do I need to create an array of textboxes or can I do this fro a datagrid?
Sean - Thanks in advance

Nov 18 '05 #2
HI Steve,

If I have a datagrid can I create empty textboxes in coumns? do you have any
code snippets?

Sean

"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I'm not following you 100%, but it sounds like its probably a good job for
either a datagrid or a repeater. Repeaters are more manual but give you
additional flexibility. Datagrids are more automatic but have limitations.
--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"Sean" <se**********@shopsmart.com.au> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
HI There,

I am making the transition from asp to asp .net, I am currenty writing an application that requires a bulk insert from a webform into SQL server,
normally I would just create rows of html textboxes and then use the
Request.Form.Count property to collect each field. What I would like to

know
is what is a good way of doing this in asp.net? Do I need to create an

array
of textboxes or can I do this fro a datagrid?
Sean - Thanks in advance


Nov 18 '05 #3
I don't think a Repeater or Datagrid is a good option for this. You can use
ASP.NET TextBox controls to achieve what you want. Just create a regular
form with as many ASP.NET TextBox controls as you want and then you can use
this code to collect values from your ASP.NET Textbox controls. Be aware
that any control you create is a child of <FORM>
(System.Web.UI.HtmlControls.HtmlForm) so you will first have to find it as a
control of your Page class, once you have found it in the control collection
you have to iterate in the HtmlForm's control collection to find the TextBox
controls. You can then add the values to an ArrayList class (a dynamic
array) and retrieve each value by its index

Hope this helps
Alan Ferrandiz
MCT;MCDBA,MCSD
MSF Practitioner

Dim aValues As New ArrayList()
Dim iCount As Integer

If Page.IsPostBack Then
Dim ctlFormulario, ctlControl As Control
For Each ctlFormulario In Me.Controls
If TypeOf (ctlFormulario) Is
System.Web.UI.HtmlControls.HtmlForm Then
For Each ctlControl In ctlFormulario.Controls
If TypeOf (ctlControl) Is TextBox Then
aValues.Add(CType(ctlControl, TextBox).Text)
Response.Write(aValues(iCount) & "<BR>")
iCount += 1
End If
Next
End If
Next
End If

"Sean" <se**********@shopsmart.com.au> escribió en el mensaje
news:#3**************@TK2MSFTNGP12.phx.gbl...
HI Steve,

If I have a datagrid can I create empty textboxes in coumns? do you have any code snippets?

Sean

"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I'm not following you 100%, but it sounds like its probably a good job for
either a datagrid or a repeater. Repeaters are more manual but give you
additional flexibility. Datagrids are more automatic but have

limitations.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"Sean" <se**********@shopsmart.com.au> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
HI There,

I am making the transition from asp to asp .net, I am currenty writing an application that requires a bulk insert from a webform into SQL server, normally I would just create rows of html textboxes and then use the
Request.Form.Count property to collect each field. What I would like

to know
is what is a good way of doing this in asp.net? Do I need to create an

array
of textboxes or can I do this fro a datagrid?
Sean - Thanks in advance



Nov 18 '05 #4
HI Alan,

Thanks for answering my question, just one other thing. If I need to create
rows of textboxes with the same name how can I acheive this? given that I
get errors if two controls have the same name.

Sean
"Alan Ferrandiz Langley" <af********@online.labroe.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I don't think a Repeater or Datagrid is a good option for this. You can use ASP.NET TextBox controls to achieve what you want. Just create a regular
form with as many ASP.NET TextBox controls as you want and then you can use this code to collect values from your ASP.NET Textbox controls. Be aware
that any control you create is a child of <FORM>
(System.Web.UI.HtmlControls.HtmlForm) so you will first have to find it as a control of your Page class, once you have found it in the control collection you have to iterate in the HtmlForm's control collection to find the TextBox controls. You can then add the values to an ArrayList class (a dynamic
array) and retrieve each value by its index

Hope this helps
Alan Ferrandiz
MCT;MCDBA,MCSD
MSF Practitioner

Dim aValues As New ArrayList()
Dim iCount As Integer

If Page.IsPostBack Then
Dim ctlFormulario, ctlControl As Control
For Each ctlFormulario In Me.Controls
If TypeOf (ctlFormulario) Is
System.Web.UI.HtmlControls.HtmlForm Then
For Each ctlControl In ctlFormulario.Controls
If TypeOf (ctlControl) Is TextBox Then
aValues.Add(CType(ctlControl, TextBox).Text)
Response.Write(aValues(iCount) & "<BR>")
iCount += 1
End If
Next
End If
Next
End If

"Sean" <se**********@shopsmart.com.au> escribió en el mensaje
news:#3**************@TK2MSFTNGP12.phx.gbl...
HI Steve,

If I have a datagrid can I create empty textboxes in coumns? do you have

any
code snippets?

Sean

"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I'm not following you 100%, but it sounds like its probably a good job for either a datagrid or a repeater. Repeaters are more manual but give you additional flexibility. Datagrids are more automatic but have

limitations.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"Sean" <se**********@shopsmart.com.au> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
> HI There,
>
> I am making the transition from asp to asp .net, I am currenty writing
an
> application that requires a bulk insert from a webform into SQL server, > normally I would just create rows of html textboxes and then use the
> Request.Form.Count property to collect each field. What I would like to know
> is what is a good way of doing this in asp.net? Do I need to create

an array
> of textboxes or can I do this fro a datagrid?
>
>
> Sean - Thanks in advance
>
>



Nov 18 '05 #5
I guess you mean controls with the same ID, which is the property that
identifies a control in the server. Well an ID has to be
unique as far as i know, but if you want to have something like a name that
is exactly the sameto your TextBox controls, you can add an attribute to the
Attributes collection of your TextBox controls.

The first time page loads you add an attribute to each TextBox control and
when the page is doing a postback you check in every control that attribute
you added. In my case i added an attribute called MyName and set it to the
value "MyId".

Alan Ferrandiz Langley
MCT, MCSD, MCDBA
MSF Practitioner

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim aValues As New ArrayList()
Dim iCount As Integer

If Page.IsPostBack Then ' page is doing postback
Dim ctlFormulario, ctlControl As Control
For Each ctlFormulario In Me.Controls
If TypeOf (ctlFormulario) Is
System.Web.UI.HtmlControls.HtmlForm Then
For Each ctlControl In ctlFormulario.Controls
If TypeOf (ctlControl) Is TextBox Then
If CType(ctlControl,
TextBox).Attributes.Item("MyName") = "MyId" Then
aValues.Add(CType(ctlControl, TextBox).Text)
Response.Write(CType(ctlControl,
TextBox).Attributes.Item("MyName") & "<BR>")
Response.Write(aValues(iCount) & "<BR>")
iCount += 1
End If
End If
Next
End If
Next
Else ' first time page loads, add same attribute to your TextBox
controls
TextBox1.Attributes.Add("MyName", "MyId")
TextBox2.Attributes.Add("MyName", "MyId")
TextBox3.Attributes.Add("MyName", "MyId")
TextBox4.Attributes.Add("MyName", "MyId")
TextBox5.Attributes.Add("MyName", "MyId")
End If

End Sub
"Sean" <se**********@shopsmart.com.au> escribió en el mensaje
news:eS**************@tk2msftngp13.phx.gbl...
HI Alan,

Thanks for answering my question, just one other thing. If I need to create rows of textboxes with the same name how can I acheive this? given that I
get errors if two controls have the same name.

Sean
"Alan Ferrandiz Langley" <af********@online.labroe.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I don't think a Repeater or Datagrid is a good option for this. You can use
ASP.NET TextBox controls to achieve what you want. Just create a regular
form with as many ASP.NET TextBox controls as you want and then you can

use
this code to collect values from your ASP.NET Textbox controls. Be aware
that any control you create is a child of <FORM>
(System.Web.UI.HtmlControls.HtmlForm) so you will first have to find it as a
control of your Page class, once you have found it in the control collection
you have to iterate in the HtmlForm's control collection to find the

TextBox
controls. You can then add the values to an ArrayList class (a dynamic
array) and retrieve each value by its index

Hope this helps
Alan Ferrandiz
MCT;MCDBA,MCSD
MSF Practitioner

Dim aValues As New ArrayList()
Dim iCount As Integer

If Page.IsPostBack Then
Dim ctlFormulario, ctlControl As Control
For Each ctlFormulario In Me.Controls
If TypeOf (ctlFormulario) Is
System.Web.UI.HtmlControls.HtmlForm Then
For Each ctlControl In ctlFormulario.Controls
If TypeOf (ctlControl) Is TextBox Then
aValues.Add(CType(ctlControl, TextBox).Text)
Response.Write(aValues(iCount) & "<BR>")
iCount += 1
End If
Next
End If
Next
End If

"Sean" <se**********@shopsmart.com.au> escribió en el mensaje
news:#3**************@TK2MSFTNGP12.phx.gbl...
HI Steve,

If I have a datagrid can I create empty textboxes in coumns? do you have
any
code snippets?

Sean

"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
> I'm not following you 100%, but it sounds like its probably a good
job for
> either a datagrid or a repeater. Repeaters are more manual but give you > additional flexibility. Datagrids are more automatic but have
limitations.
>
> --
> I hope this helps,
> Steve C. Orr, MCSD, MVP
> http://Steve.Orr.net
>
>
> "Sean" <se**********@shopsmart.com.au> wrote in message
> news:%2****************@TK2MSFTNGP12.phx.gbl...
> > HI There,
> >
> > I am making the transition from asp to asp .net, I am currenty writing an
> > application that requires a bulk insert from a webform into SQL

server,
> > normally I would just create rows of html textboxes and then use
the > > Request.Form.Count property to collect each field. What I would

like to
> know
> > is what is a good way of doing this in asp.net? Do I need to

create an > array
> > of textboxes or can I do this fro a datagrid?
> >
> >
> > Sean - Thanks in advance
> >
> >
>
>



Nov 18 '05 #6
HI Alan,

I tried your code as it was and I could not get it to work at all, I change
some of the properties and it seems now to be working but iterates through
the controls a number of times. I have tried to exit the for loop when the
last control has been displayed but this is not working, what am I doing
wrong?

Sean - thanks in advance for your answer.
Dim aValues As New ArrayList()
Dim iCount As Integer
Dim counter as Integer

If Page.IsPostBack Then
'Dim myConnection as New
SqlConnection(ConfigurationSettings.AppSettings("c onnectionString"))

'myConnection.Open()

Dim ctlFormulario, ctlControl As Control
For Each ctlFormulario In Me.Controls
'If TypeOf (ctlFormulario) Is
System.Web.UI.HtmlControls.HtmlForm Then
If TypeOf (ctlFormulario) Is
System.Web.UI.WebControls.TextBox Then
'For Each ctlControl In ctlFormulario.Controls
For Each ctlControl In ME.Controls

If TypeOf (ctlControl) Is TextBox Then
aValues.Add(CType(ctlControl, TextBox).Text)
response.write (CType(ctlControl, TextBox).ID & "<BR>")
Response.Write(" " & aValues(iCount) & "<BR>")

iCount += 1
counter += 1

If CType(ctlControl, TextBox).ID = "txtPrice6"
Then Exit For

'Dim myCommand As New SqlCommand("ListingAddFertigation",
myConnection)
'myCommand.CommandType = CommandType.StoredProcedure
End If
Next
End If
Next
End If

!--- form code snippet

<tr>
<td><asp:TextBox id="txtQuantity6" width="30" maxlength="30" runat="server"
/></td>
<td><asp:TextBox id="txtDescription6" width="150" style="height:55px;"
maxlength="250" runat="server" /></td>
<td><asp:TextBox id="txtSize6" width="30" maxlength="30" runat="server"
/></td>
<td><asp:TextBox id="txtMaterial6" width="150" style="height:55px;"
maxlength="250" runat="server" /></td>
<td><asp:TextBox id="txtPrice6" width="30" maxlength="30" runat="server"
/></td>
</tr>
"Alan Ferrandiz Langley" <af********@online.labroe.com> wrote in message
news:#E**************@TK2MSFTNGP10.phx.gbl...
I guess you mean controls with the same ID, which is the property that
identifies a control in the server. Well an ID has to be
unique as far as i know, but if you want to have something like a name that is exactly the sameto your TextBox controls, you can add an attribute to the Attributes collection of your TextBox controls.

The first time page loads you add an attribute to each TextBox control and
when the page is doing a postback you check in every control that attribute you added. In my case i added an attribute called MyName and set it to the
value "MyId".

Alan Ferrandiz Langley
MCT, MCSD, MCDBA
MSF Practitioner

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim aValues As New ArrayList()
Dim iCount As Integer

If Page.IsPostBack Then ' page is doing postback
Dim ctlFormulario, ctlControl As Control
For Each ctlFormulario In Me.Controls
If TypeOf (ctlFormulario) Is
System.Web.UI.HtmlControls.HtmlForm Then
For Each ctlControl In ctlFormulario.Controls
If TypeOf (ctlControl) Is TextBox Then
If CType(ctlControl,
TextBox).Attributes.Item("MyName") = "MyId" Then
aValues.Add(CType(ctlControl, TextBox).Text) Response.Write(CType(ctlControl,
TextBox).Attributes.Item("MyName") & "<BR>")
Response.Write(aValues(iCount) & "<BR>")
iCount += 1
End If
End If
Next
End If
Next
Else ' first time page loads, add same attribute to your TextBox
controls
TextBox1.Attributes.Add("MyName", "MyId")
TextBox2.Attributes.Add("MyName", "MyId")
TextBox3.Attributes.Add("MyName", "MyId")
TextBox4.Attributes.Add("MyName", "MyId")
TextBox5.Attributes.Add("MyName", "MyId")
End If

End Sub
"Sean" <se**********@shopsmart.com.au> escribió en el mensaje
news:eS**************@tk2msftngp13.phx.gbl...
HI Alan,

Thanks for answering my question, just one other thing. If I need to create
rows of textboxes with the same name how can I acheive this? given that I
get errors if two controls have the same name.

Sean
"Alan Ferrandiz Langley" <af********@online.labroe.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I don't think a Repeater or Datagrid is a good option for this. You can
use
ASP.NET TextBox controls to achieve what you want. Just create a
regular form with as many ASP.NET TextBox controls as you want and then you can use
this code to collect values from your ASP.NET Textbox controls. Be
aware that any control you create is a child of <FORM>
(System.Web.UI.HtmlControls.HtmlForm) so you will first have to find it as
a
control of your Page class, once you have found it in the control

collection
you have to iterate in the HtmlForm's control collection to find the

TextBox
controls. You can then add the values to an ArrayList class (a dynamic
array) and retrieve each value by its index

Hope this helps
Alan Ferrandiz
MCT;MCDBA,MCSD
MSF Practitioner

Dim aValues As New ArrayList()
Dim iCount As Integer

If Page.IsPostBack Then
Dim ctlFormulario, ctlControl As Control
For Each ctlFormulario In Me.Controls
If TypeOf (ctlFormulario) Is
System.Web.UI.HtmlControls.HtmlForm Then
For Each ctlControl In ctlFormulario.Controls
If TypeOf (ctlControl) Is TextBox Then
aValues.Add(CType(ctlControl,

TextBox).Text) Response.Write(aValues(iCount) & "<BR>")
iCount += 1
End If
Next
End If
Next
End If

"Sean" <se**********@shopsmart.com.au> escribió en el mensaje
news:#3**************@TK2MSFTNGP12.phx.gbl...
> HI Steve,
>
> If I have a datagrid can I create empty textboxes in coumns? do you

have any
> code snippets?
>
> Sean
>
> "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
> news:%2****************@TK2MSFTNGP10.phx.gbl...
> > I'm not following you 100%, but it sounds like its probably a good job for
> > either a datagrid or a repeater. Repeaters are more manual but
give you
> > additional flexibility. Datagrids are more automatic but have
> limitations.
> >
> > --
> > I hope this helps,
> > Steve C. Orr, MCSD, MVP
> > http://Steve.Orr.net
> >
> >
> > "Sean" <se**********@shopsmart.com.au> wrote in message
> > news:%2****************@TK2MSFTNGP12.phx.gbl...
> > > HI There,
> > >
> > > I am making the transition from asp to asp .net, I am currenty

writing
> an
> > > application that requires a bulk insert from a webform into SQL
server,
> > > normally I would just create rows of html textboxes and then use

the > > > Request.Form.Count property to collect each field. What I would like to
> > know
> > > is what is a good way of doing this in asp.net? Do I need to

create
an
> > array
> > > of textboxes or can I do this fro a datagrid?
> > >
> > >
> > > Sean - Thanks in advance
> > >
> > >
> >
> >
>
>



Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Paul Rowe | last post by:
Hi "You" I have two collection types declared at the SQL level. 1. Do you know of any known bugs with the BULK COLLECT clause used with the TABLE operator? I have a situation now where I am...
2
by: php newbie | last post by:
Hello, I am trying to load a simple tab-delimited data file to SQL Server. I created a format file to go with it, since the data file differs from the destination table in number of columns. ...
5
by: me | last post by:
I'm also having problems getting the bulk insert to work. I don't know anything about it except what I've gleened from BOL but I'm not seeming to get anywhere...Hopefully there is some little (or...
7
by: iqbal | last post by:
Hi all, We have an application through which we are bulk inserting rows into a view. The definition of the view is such that it selects columns from a table on a remote server. I have added the...
2
by: Niraj | last post by:
Hi, I am trying to do bulk insert of binary data (array of bytes) in an Oracle table. The data type of the table is BLOB. I am using Oracle Objects for OLE (OO4O) in C++. The binary data that I...
20
by: akej via SQLMonster.com | last post by:
Hi, i have table with 15 columns CREATE TABLE . ( PRIMARY KEY , NULL , NULL , NULL , NULL , (50) NULL , NULL
6
by: pk | last post by:
Sorry for the piece-by-piece nature of this post, I moved it from a dormant group to this one and it was 3 separate posts in the other group. Anyway... I'm trying to bulk insert a text file of...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
1
by: teo | last post by:
Hallo, I'm performing a mass insertion from a text file to a db table with AdoNet commands, like this: myCommand.CommandText = "BULK INSERT ..." from a Win form no problem
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.