0

I have textbox like =101,102,103,104

I want to save this value in ArrayList in following format

GVNo
-----
101
102
103
104

Later save in following table in gvno column

My table is issuedDetailId, detailId, gvno` in SQL Server 2008 and vb.net 2010

then how do i store in detail table using for loops i never used arralylist before. and gvno field in table is numeric type

2
  • 1
    Why save as an array? If all you want to do is save it to a DB, you can go straight from the string to executing your insert queries. Commented Mar 15, 2013 at 6:14
  • can u tell me how to do it plz Commented Mar 15, 2013 at 6:33

3 Answers 3

2

Dim vasList() As String = Split(TextBox1.Text,",")

Sign up to request clarification or add additional context in comments.

3 Comments

then how do i store in detail table using for loops i never used arralylist before. thanks
I think OP has asked to save the splitted datum in to an arraylist.?
ArrayLists are essentially deprecated as they're untyped - you need to use casts with them - and they're slower and less space efficient for value types because they require the items to be boxed. Generic lists were introduced with .Net 2.0 and are the way to go. Often a List is better than an array, with few downsides. They are also much more memory efficient. As these collections are part of the .Net Base Class Library, this also applies to C# and to any .Net language which supports generics.
1

This code will store the splitted text into the arraylist,

Dim xArrayList As ArrayList = New ArrayList(TextBox1.text.Split(","))

Comments

0

If all you want to save your string entries straight to the database I think you should do something like this:

    Dim test As String = "string1, string2, string3, string4"

    With MyDBConnection
        Dim transaction As OleDbTransaction
        Try
            Call .Open()
            transaction = .BeginTransaction()
            With .CreateCommand()
                .Transaction = transaction
                For Each entry As String In test.Split(","c)
                    .CommandText = String.Format("INSERT INTO [Table] ([Column]) VALUES ({0})", entry)
                    Call .ExecuteNonQuery()
                Next
            End With
            Call transaction.Commit()
        Catch ex As Exception
            ' Handle exception here
            Call transaction.Rollback()
        Finally
            Call .Close()
        End Try
    End With

This will take the strings and insert them as is into the database. As you are taking user input you should really use a parameters in your query instead of a simple string like I am doing here...

If you need to do validation the string, use the '.split' function before accessing the database. You can do something like Dim MyArray() as string = MyInput.Split(","c) to dump the values into an array.

Hope this helps you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.