Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table in mydatabsae with 10 columns i am trying to populate an arraylist with those and then the first column with the name Submit_id to convert it in my array list from column to row how can i do that?Thanks.


Imports System
Imports System.Data
Imports System.Data.SqlClient

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Public Function ConvertDatasettoArrayList() As ArrayList
        Dim ds As New DataSet()
        
        Dim list As New ArrayList()
        Using con As New SqlConnection("server=localhost;database=Starbulk;Integrated Security=true;")
            Using cmd As New SqlCommand("SELECT * FROM Table_1", con)
                con.Open()
                Dim da As New SqlDataAdapter(cmd)
                da.Fill(ds)

                For Each dtrow As DataRow In ds.Tables(0).Rows
                    list.Add(dtrow)
                Next
            End Using
        End Using
        DataGridView1.DataSource = ds

        Return list
    End Function

    Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
       
    End Sub

    

End Class


Also i have this code to try with dataadapters and readers but with no luckk either if you are interested in that code i can explain it further

VB
Imports System
Imports System.Data
Imports System.Data.SqlClient

Public Class Final
    Dim objConnection As New SqlConnection _
    ("server=localhost;database=Starbulk;Integrated Security=true;")
    Dim Table_1 As New SqlDataAdapter()
    Dim list As New SqlDataAdapter()
    Dim Table_1_reader As SqlDataReader





    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim Submit_ID As Integer
        Dim Form_ID As Integer
        Dim Control_ID As Integer
        Dim Row_NO As Integer
        Dim Table_ID As Integer
        Dim Int_Val As Integer
        Dim Decimal_Val As Decimal
        Dim String_Val As String
        Dim Boolean_Val As Integer



        Table_1.SelectCommand = New SqlCommand()
        Table_1.SelectCommand.Connection = objConnection
        Table_1.SelectCommand.CommandText = "SELECT * FROM Table_1 ORDER BY Submit_ID , Control_ID"
        Table_1.SelectCommand.CommandType = CommandType.Text

        objConnection.Open()
        Table_1_reader = Table_1.SelectCommand.ExecuteReader()


        Do While Table_1_reader.Read()
            Submit_ID = Table_1_reader("Submit_ID")
            Control_ID = Table_1_reader("Control_ID")
            If Submit_ID <> Table_1_reader("Submit_ID") Then
                Submit_ID = Table_1_reader("Submit_ID")
                list.SelectCommand = New SqlCommand()
                list.SelectCommand.Connection = objConnection
                list.SelectCommand.CommandText = "INSERT INTO Table_1 (Submit_ID,Form_ID,Control_ID,Row_NO,Table_ID,Int_Val,Decimal_Val,Datetime_Val,String_Val,Boolean_Val) VALUES (" & Submit_ID & ",'" & Form_ID & "," & Control_ID _
& "," & Row_NO & ", '" & Table_ID & ", '" & Int_Val & ", " & Decimal_Val & ", '" & String_Val & ", '" & Boolean_Val & " ' )"
                list.SelectCommand.CommandType = CommandType.Text
                list.SelectCommand.ExecuteNonQuery()

            End If
            Select Case Control_ID
                Case 15569


            End Select



        Loop
        Application.DoEvents()
        Table_1_reader.Close()



        objConnection.Close()
        Table_1 = Nothing
        objConnection = Nothing
    End Sub
End Class
Posted
Updated 23-Jan-15 1:07am
v5
Comments
DamithSL 23-Jan-15 5:50am    
C#, VB or VB.net?
what have you tried so far?
Member 10059109 23-Jan-15 5:56am    
C# and VB but i prefer VB
DamithSL 23-Jan-15 6:00am    
have you able to read data from database? can you update the question with the code you tried?
explain where you stuck with your code
Member 10059109 23-Jan-15 7:06am    
yes i am the connection is solid i cant configure my data though
Tejas Vaishnav 23-Jan-15 6:16am    
What you want to store in your arraylist?

1 solution

chnage
VB
list.Add(dtrow)

to
VB
list.Add(dtrow.Item("Submit_id"))
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900