473,398 Members | 2,404 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,398 software developers and data experts.

Dynamic Arrays in ASP.NET?

I am converting an ASP page to asp.net. In this application, a user can
enter a list of numbers, separated by commas. The relationship involved
is 1 to M and I never know how many different numbers the user will
enter.
I am getting a 'specified cast not valid' error. While I'm not 100% it
is the array, This is the block of code that I have narrowed down to
causing the problem.
I've spent some time reading on the net about the differences in arrays
in vb.net and am wondering if the split function I am using isn't the
best route to go.

Please give any pointers about arrays or suggestions for what might
cause that specific error message.

In old ASP, my code looked like this:
dim woPrefix
dim aryWO
dim I
woPrefix = "ASHC"

aryWO = split(session("WO"),",",-1)

set rst1 = cmd1.Execute()
For I = 0 to UBound(aryWO)
if session("flgType") = "e" or Instr(1,session("WO"),"ASHC") then
sqlCmd = sqlCmd + "Insert into contractOutWO Values(" &
session("ID") & ",'" & aryWO(I) & "') "
else
sqlCmd = sqlCmd + "Insert into contractOutWO Values(" &
session("ID") & ",'" & woPrefix & aryWO(I) & "') "
end if
Next

This is what I have in my .NET app:
Dim woPrefix As String
Dim aryWO As Array
Dim I As Integer
woPrefix = "ASHC"

aryWO = Split(txtWO.Text, ",", -1)

SqlSelectCommand1.CommandType = CommandType.Text
SqlSelectCommand1.CommandText = "Delete from
contractOutWO where ID ='" & lblID.Text & "'"
SqlSelectCommand1.ExecuteNonQuery()
For I = 0 To UBound(aryWO)
If ddlCOType.SelectedValue = "E" Or InStr(1,
txtWO.Text, "ASHC") Then
SqlSelectCommand1.CommandText =
SqlSelectCommand1.CommandText + "Insert into contractOutWO Values('" &
lblID.Text & "','" & aryWO(I) & "') "
Else
SqlSelectCommand1 =
SqlSelectCommand1.CommandText + "Insert into contractOutWO Values('" &
lblID.Text & "','" & woPrefix & aryWO(I) & "') "
End If
If Len(SqlSelectCommand1.CommandText) > 0 Then
SqlSelectCommand1.ExecuteNonQuery()
End If
Next

Dec 8 '05 #1
7 1162
using arraylist insteal of array in dot net
tony
<tj*****@phenom-biz.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
I am converting an ASP page to asp.net. In this application, a user can
enter a list of numbers, separated by commas. The relationship involved
is 1 to M and I never know how many different numbers the user will
enter.
I am getting a 'specified cast not valid' error. While I'm not 100% it
is the array, This is the block of code that I have narrowed down to
causing the problem.
I've spent some time reading on the net about the differences in arrays
in vb.net and am wondering if the split function I am using isn't the
best route to go.

Please give any pointers about arrays or suggestions for what might
cause that specific error message.

In old ASP, my code looked like this:
dim woPrefix
dim aryWO
dim I
woPrefix = "ASHC"

aryWO = split(session("WO"),",",-1)

set rst1 = cmd1.Execute()
For I = 0 to UBound(aryWO)
if session("flgType") = "e" or Instr(1,session("WO"),"ASHC") then
sqlCmd = sqlCmd + "Insert into contractOutWO Values(" &
session("ID") & ",'" & aryWO(I) & "') "
else
sqlCmd = sqlCmd + "Insert into contractOutWO Values(" &
session("ID") & ",'" & woPrefix & aryWO(I) & "') "
end if
Next

This is what I have in my .NET app:
Dim woPrefix As String
Dim aryWO As Array
Dim I As Integer
woPrefix = "ASHC"

aryWO = Split(txtWO.Text, ",", -1)

SqlSelectCommand1.CommandType = CommandType.Text
SqlSelectCommand1.CommandText = "Delete from
contractOutWO where ID ='" & lblID.Text & "'"
SqlSelectCommand1.ExecuteNonQuery()
For I = 0 To UBound(aryWO)
If ddlCOType.SelectedValue = "E" Or InStr(1,
txtWO.Text, "ASHC") Then
SqlSelectCommand1.CommandText =
SqlSelectCommand1.CommandText + "Insert into contractOutWO Values('" &
lblID.Text & "','" & aryWO(I) & "') "
Else
SqlSelectCommand1 =
SqlSelectCommand1.CommandText + "Insert into contractOutWO Values('" &
lblID.Text & "','" & woPrefix & aryWO(I) & "') "
End If
If Len(SqlSelectCommand1.CommandText) > 0 Then
SqlSelectCommand1.ExecuteNonQuery()
End If
Next

Dec 9 '05 #2
Hi,

First of all if you are using VSNet with VBNet than set on Option Strict to
On. Probably because all still upgraders from VB6 to VBNet is this by
default of.
Dim woPrefix as String = "ASHC"
Dim aryWO as Array = Split(txtWO.Text, ",", -1)
SqlSelectCommand1.CommandType = CommandType.Text 'this is default
SqlSelectCommand1.CommandText = "Delete from contractOutWO where ID ='" &
lblID.Text & "'"
SqlSelectCommand1.ExecuteNonQuery()
For i as Integer = 0 To AryWO.length - 1
If ddlCOType.SelectedValue = "E" Or InStr(1, txtWO.Text,
"ASHC") Then
SqlSelectCommand1.CommandText =
SqlSelectCommand1.CommandText + "Insert into
contractOutWO Values('" &

Do not use the ambigous + to concatinate in VB Net. With Option Strict of it
can give you a lot of trouble, it can than be used in the late binding as an
real plus to add.

I cannot see it deeper, because of that long string. The change that this
plus is your error is however high.
If that is not the problem than reply here.

Have as well beside this a look at commandparameters. That this sample is
for windowforms does not matter in this case.

http://www.vb-tips.com/default.aspx?...6-7139b8970071

This is the most simple sample there are more about this on our website just
search for 'parameters'

Did you know by the way that there is a special VB Net language newsgroup.

microsoft.public.dotnet.languages.vb

I hope this helps so far,

Cor
Dec 9 '05 #3
Tony
using arraylist insteal of array in dot net
tony


That is not the case here, the split wants a fixed array.

Cor
Dec 9 '05 #4
Thanks. You've all given me a lot to look at. I am familiar with the VB
Net group. I posted here because I wasn't totally sure where the error
was coming from and thought maybe a more general group could provide
the answer. I appreciate your feedback. If this doesn't work, I'll
definitely post back.
Thank you.

Dec 9 '05 #5
For others who might have the same problem:

I had to change this:

dim woPrefix
dim aryWO
dim I
woPrefix = "ASHC"
aryWO = split(session("WO"),",",-1)

to this:

Dim woPrefix As String
Dim aryWO() As String
Dim I As Integer
woPrefix = "ASHC"
aryWO = txtWO.Text.Split(",")

I tried setting Option Strict to On, however, it gave me errors I
didn't understand. Mainly, I wanted to display the forms ID# once it
had been saved in the database. I was setting the text of a label to
display the output param of a previous stored procedure. It works fine
without option strict, but not with.
I have other apps that do the same thing and work well. So, because I'm
on a time crunch I thought I'd leave it as is and work on other things
more pressing.

Would you know why I got an error on the setting of label text?
It said 'Option strict disallows implicit conversions from
System.object to string'

Dec 12 '05 #6
Tjonsek,

It is very simple.

Option Strict Of acts like VB6. An object is translated at runtime to its
type accoording to the value that is used, this is very useful for all
programs that has to be converted from VB6 to VBNet.

However

VB Net with option Strict Of is comparable in speed with VB6
VB Net with option Strict On has the same speed as C#

But if you buy more expensive hardware you can of course compensate that.

I hope this helps,

Cor
Dec 12 '05 #7
Thanks. Appreciate it.

Dec 12 '05 #8

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

Similar topics

3
by: meyousikmann | last post by:
The following code just sets up and fills a dynamic array of integers. #include <cstdlib> int main() { int* intArray = NULL; int count; count = 20;
4
by: Scott Lyons | last post by:
Hey all, Can someone help me figure out how to pass a dynamic array into a function? Its been giving me some trouble, and my textbook of course doesnt cover the issue. Its probably something...
3
by: genc ymeri | last post by:
Hi, What can I use in C# for dynamic arrays ???? I have some records (struts in ..Net) and want to store them in a dynamic "arrays" or object list. I noticed the in C# arrays' length can't be...
60
by: Peter Olcott | last post by:
I need to know how to get the solution mentioned below to work. The solution is from gbayles Jan 29 2001, 12:50 pm, link is provided below: >...
4
by: learnfpga | last post by:
Here is a little code I wrote to add the numbers input by the user.....I was wondering if its possible to have the same functionality without using dynamic arrays.....just curious..... ...
2
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs,...
4
by: hobbes992 | last post by:
Howdy folks, I've been working on a c project, compiling using gcc, and I've reached a problem. The assignment requires creation of a two-level directory file system. No files have to be added or...
1
by: KioKrofov | last post by:
Hello, I am trying to find out how Dynamic Arrays are actually stored in memory. Really, I want to know how Vectors are stored in memory, but I deduce they are stored the same way. If you...
2
by: headware | last post by:
Do dynamic arrays declared using ReDim have to be freed? I assume that if it's an array of dynamically created objects (e.g. Scripting.Dictionary), each one of those objects will have to be set to...
4
by: Sunny | last post by:
Hi, Is there a way in javascript to create Dynamic arrays or arrays on fly. Something Like: var "ptsgN"+sd = new Array(); Here sd is incrementing by 1. I have lots of data that I am...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.