在VB中转换arraylist中的talbe [英] Convert talbe in arraylist in VB
本文介绍了在VB中转换arraylist中的talbe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在mydatabsae中有一个包含10列的表我正在尝试用这些列填充一个arraylist然后使用名称Submit_id的第一列将它在我的数组列表中从列到行转换我怎么能这样做?谢谢。< br $>
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
我也有这个代码尝试使用dataadapters和读者但是如果你对该代码感兴趣,我可以进一步解释它没有运气
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
推荐答案
chnage
chnage
list.Add(dtrow)
to
to
list.Add(dtrow.Item("Submit_id"))
这篇关于在VB中转换arraylist中的talbe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文