 |
| ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

June 29th, 2004, 05:31 AM
|
|
Authorized User
|
|
Join Date: Jun 2004
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Store Data From textboxes which form Table
Hi Frnds,
I am i new member of this forum and after going thru the stuff posted on this forum i thought to mail one of my problem to this forum.
I am creating a web form usinf VB.NET and i am using MS SQL Server 2000 as my backend to store my data.
Now my front page look some what like this
Division
Alpha Beta Gamma
Regions
East textBox1 textBox2 textbox3
West textbox4 textbox5 textbox6
North textbox7 textbox8 textbox9
South textbox10 textbox11 textbox12
Now there will be some values that will be entered in the textboxes above and this values that are entered in the textboxes have to be stored into the table in the database.
The Fields of the table are
Sr no.
Region_Name
Division_Name
No_Of_Entries
I wud like to know how should i travese there textboxes to accept the values from them and then store it into the database
So my frnds i have provided you with all the possible details that i can with all my knowledge. If anyone who has solved thistype of problem or anyone who can suggest some steps on it can pl come froward to help me out in this.
Any help will be appreciated.
LOL-:)
Cheers,
Vishal
Life is not the Triumph but the Struggle
__________________
Life is not the Triumph but the Struggle
|
|

June 29th, 2004, 08:22 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Is this a fixed set of textboxes? If those are all the textboxes you need, you just have to access each textbox and do what you need for each one. The best advice I could provide is to create a function that does what you need (insert/update data?) then call this function for each textbox with the respective data from the textbox's position in the matrix:
DoSomething("East", "Alpha", textBox1)
DoSomething("East", "Beta", textBox2)
DoSomething("East", "Gamma", textBox3)
DoSomething("West", "Alpha", textBox4)
DoSomething("West", "Beta", textBox5)
DoSomething("West", "Gamma", textBox6)
DoSomething("North", "Alpha", textBox7)
DoSomething("North", "Beta", textBox8)
DoSomething("North", "Gamma", textBox9)
DoSomething("South", "Alpha", textBox10)
DoSomething("South", "Beta", textBox11)
DoSomething("South", "Gamma", textBox12)
Sub DoSomething(strRegion, strDivision, txtTextBox)
'Do what you need here
End Sub
Peter
-------------------------
Work smarter, not harder
|
|

June 29th, 2004, 11:17 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
|
|
Well there r sme ways to store data in DB.
I suggest to make a Storeed Procedure to insert ur values in its Table. Then put a SqlCommand to ur Page & Set its to ur SP. Then Set its Parameters to ur TextBoxes & so on...
HTH.
[u] A simple sample:</u>
Code:
ConnObj.Open();
CommObj.Parameters["@FName"].Value = TextBox1.Text;
CommObj.Parameters["@LName"].Value = TextBox2.Text;
CommObj.Parameters["@Father"].Value = TextBox3.Text;
CommObj.ExecuteNonQuery();
ConnObj.Close();
Always:),
Hovik Melkomian.
|
|

June 29th, 2004, 11:48 PM
|
|
Authorized User
|
|
Join Date: Jun 2004
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Planoie for the help, but this wud hardcode the webpage, thus making it more of static in nature. For now yes the number of textboxes are fixed in the webform, but it may change later.
So if u have any idea, to do it thru looping or something else then wud definately like to know it from u.
Here actually, initally all the textboxes will have default values set as 0, and then say if the values are changed for the textboxes then we need to take the changed values and store it into the database, only fro the textboxes whose value is changed.
Hope u can understand my problem.
thanks,
Cheers,
LOL-:)
Vishal
Life is not the Triumph but the Struggle
|
|

June 30th, 2004, 06:30 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Well you can do this with looping. You can loop from 1 to n and construct a control name from "textbox" + i then use the FindControl() method of the page to find an existing control with that ID. The harder part is knowing what region and division that textbox is associated with. You could follow a naming convention like this:
txtWest_1 txtWest_2 txtWest_3
txtEast_1 txtEast_2 txtEast_3
etc.
But this then requires several loops and hasn't really solved your problem. Unless you are actually constructing the textboxes dynamically, I'd just stick with individual calls for each. If you need to change them, then change them and the individual calls. If you get to the point where you actually have to create the text boxes dynamically, then you'll have to rethink the whole thing and use something like a datagrid to construct the matrix.
|
|

June 30th, 2004, 07:34 AM
|
|
Authorized User
|
|
Join Date: Jun 2004
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Once again,
Good to have a clue from you, will try to implement it, if possible, an dhope it works...
Can u pls tell me say if i name the textboxes for example
(EAST,ALPHA) =(0,0), there fore textbox id =0_0
(EAST,BETA) =(0,1), there fore textbox id =0_1
(EAST,GAMMA) =(0,2), there fore textbox id =0_2
(WEST,ALPHA) =(1,0), there fore textbox id =1_0
(WEST,BETA) =(1,1), there fore textbox id =1_1
Then is ti possible to loop in this fashion,
for i =1 to n
for j=i to n-1
if (i_j.Text) > 0 then
DoSomething(Say Call the insert function)
End if
Next j
Next i
How about this type of looping, I have't tried it as just thought of it writing u the reply.
If you find this good then pl do tell me abt it, or if u can help me to enhance this code then it wud be awesome.
Hope to have a reply asap
thanks,
Cheers,
LOL-:)
Vishal
Life is not the Triumph but the Struggle
|
|

June 30th, 2004, 08:15 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
You certainly could name them like this, and you would have a loop that's as optimized as I could make it.
Another idea could be this: You have a matrix (grid) of textboxes, so you'll always have 2 dimensions. Therefore, create two arrays of the strings representing each column and row. Because you need those column and row headers for data in the insert/update (don't you?). Then you can iterate thru those and have them available for the database call...
Dim aryRegions() As String = {"East", "West", "North", "South"}
Dim aryDivisions() As String = {"Alpha", "Beta", "Gamma"}
Dim strRegion, strDivision As String
For Each strRegion In aryRegions
For Each strDivision In aryDivisions
objTextBox = FindControl("txt" & strRegion & "_" strDivision)
If objTextBox.Text > 0 Then
'DoSomething(strRegion, strDivision, objTextBox.Text)
End If
Next
Next
|
|

June 30th, 2004, 11:10 PM
|
|
Authorized User
|
|
Join Date: Jun 2004
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for the idea Planoie and will definately try to implement what you mentioned. Will Get back to u if there is any real problem while implementing it.
Thanks Once Again,
Cheers,
LOL-:)
Vishal
Life is not the Triumph but the Struggle
|
|
 |