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
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