下一步I am trying to get a listing of all records in a dataset to display in a table. I have tried several options I have found through research and get no where. Anyone have any easier ideas? Being new to programming in general, this have given me fits. Here''s the last thing I tried: strSQL = "Select * from Safety_Data where xref_id=" & strTypePull & "and Shift_ID=" & strShiftPull & "and Date=''" & strSelDate & "''" Dim objDataSet As New Data.DataSet Dim objConn As New Data.SqlClient.SqlConnection("Data Source=XXXXXX;Initial Catalog=XXXXXX;User ID=XXXXXX;password=XXXXXX;") Dim objCmd As New Data.SqlClient.SqlDataAdapter(strSQL, objConn) objConn.Open() objCmd.Fill(objDataSet) Dim objDC As Data.DataColumn Dim objDT As Data.DataRow For Each objDT In objDataSet.Tables(0).Rows For Each objDC In objDataSet.Tables(0).Columns txtRecID = objDataSet.Tables(0).Rows(0)("RID").ToString() txtDate = objDataSet.Tables(0).Rows(0)("Date").ToString() txtShift = objDataSet.Tables(0).Rows(0)("Shift_ID").ToString( ) txtType = objDataSet.Tables(0).Rows(0)("Xref_ID").ToString() TxtOccNotes = objDataSet.Tables(0).Rows(0)("Notes").ToString() Next Next推荐答案 您在寻找什么?所有的行? 根据你的查询,似乎objDataSet只有一个表所以 objDataSet.Tables(0) What are you looking for? All the rows? Based on your query it would appear that objDataSet will only have one table soobjDataSet.Tables(0) 展开 | 选择 | Wrap | 行号 您不需要循环遍历列的foreach循环。可以通过循环遍历行来引用列。 row(i)(列名) 删除foreach循环循环遍历列,代码应该适合你。 Nathan You don''t need the foreach loop that loops through the columns. The columns can be referenced by looping through the rows as you are doing. row(i)(columnname) Remove the foreach loop that loops through the columns and the code should work properly for you. Nathan 这是更改的代码。我在数据集中有3条记录,但它只显示一条。 Dim objDC As Data.DataColumn Dim objDT As Data.DataRow Dim i As Integer for each objDT in objDataSet.Tables(0).Rows txtRecID.Text = objDataSet.Tables(0).Rows (i)(RID)。ToString() txtDate.Text = objDataSet.Tables(0).Rows(i)(" Date")。ToString() txtShift.Text = objDataSet.Tables(0).Rows(i)(" Shift_ID")。ToString() txtType.Text = objDataSet.Tables(0).Rows( i)(Xref_ID)。ToString() TxtOccNotes.Text = objDataSet.Tables(0).Rows(i)(" Notes")。ToString() 下一步This is the changed code. I have 3 records in dataset but it only displays one. Dim objDC As Data.DataColumn Dim objDT As Data.DataRow Dim i As Integer For Each objDT In objDataSet.Tables(0).Rows txtRecID.Text = objDataSet.Tables(0).Rows(i)("RID").ToString() txtDate.Text = objDataSet.Tables(0).Rows(i)("Date").ToString() txtShift.Text = objDataSet.Tables(0).Rows(i)("Shift_ID").ToString( ) txtType.Text = objDataSet.Tables(0).Rows(i)("Xref_ID").ToString() TxtOccNotes.Text = objDataSet.Tables(0).Rows(i)("Notes").ToString() Next 这篇关于列出DataSet记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-31 01:51