我试图将整行的列添加到组合框中。 当我尝试它时,要么只显示列的最后一行,要么只显示最后一行35次。
我缺少什么?这真让我抓狂。我为评论的线路道歉,我正在尝试一些不同的编码。
Option Strict On
Imports System.Data.OleDb
Imports ShadowLogin.GlobalVariables
Public Class DeptNewSch
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
ShadowMain.Show()
End Sub
Private Sub DeptNewSch_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim CourseArray(35, 2) As String
Using cnnOLEDB = New OleDbConnection(strConnectionString)
Dim NewSchDS As DataSet
Dim NewSchTables As DataTableCollection
Dim NewSchsource1 As New BindingSource
NewSchDS = New DataSet
NewSchTables = NewSchDS.Tables
Using cmd As New OleDbCommand("SELECT ClassSection.CourseTitle AS Course, ClassSection.SectionNumber AS [Section Number], ClassSection.ScheduleNumber AS [Schedule Number], Course.ShortTitle AS [Course Title], Course.Units, ClassSection.Type AS Format, ClassSection.TimeSlot AS [Days / Time], ClassSection.RoomID AS Location, Faculty.[First Name], Faculty.[Last Name], Classroom.MaxCapacity AS Seats FROM [Classroom], [ClassSection], [Faculty], [Course] WHERE (ClassSection.FRedID = Faculty.FRedID) AND Course.CourseTitle = ClassSection.CourseTitle AND Classroom.RoomID = ClassSection.RoomID AND ClassSection.ScheduleYear=@Year AND ClassSection.Semester=@Semester;", cnnOLEDB)
cmd.Parameters.Add("@Year", OleDbType.VarWChar).Value = Convert.ToInt32(strYear.ToString())
cmd.Parameters.Add("@Semester", OleDbType.VarWChar).Value = strSemester.ToString()
Using NewSchDA As OleDbDataAdapter = New OleDbDataAdapter(cmd)
NewSchDA.Fill(NewSchDS, "New Semester") 'Change items to your database name
Dim view As New DataView(NewSchTables(0))
NewSchsource1.DataSource = view
dgNewSch.DataSource = view
Me.dgNewSch.Columns("Course").Width = 60
Me.dgNewSch.Columns("Section Number").Width = 50
Me.dgNewSch.Columns("Schedule Number").Width = 60
Me.dgNewSch.Columns("Course Title").Width = 190
Me.dgNewSch.Columns("Units").Width = 40
Me.dgNewSch.Columns("Format").Width = 70
Me.dgNewSch.Columns("Days / Time").Width = 100
Me.dgNewSch.Columns("Location").Width = 70
Me.dgNewSch.Columns("First Name").Width = 80
Me.dgNewSch.Columns("Last Name").Width = 80
Me.dgNewSch.Columns("Seats").Width = 50
End Using
End Using
End Using
'Connect to Database and get the registration information
Using cnnOLEDB = New OleDbConnection(strConnectionString)
' Query the classschedule table for start of semester datas
Using cmdOleDB = New OleDbCommand("SELECT [CourseTitle], [ShortTitle],[Units] FROM [Course] WHERE rownumber =@row", cnnOLEDB)
cnnOLEDB.Open()
Using rdrOLEDB = cmdOleDB.ExecuteReader
While rdrOLEDB.Read
Dim l As Integer
For l = 0 To 35
'cmdOleDB.Parameters.Add("@row", OleDbType.VarWChar).Value = l
CourseArray(l, 0) = rdrOLEDB.Item(0).ToString
CourseArray(l, 1) = rdrOLEDB.Item(1).ToString
CourseArray(l, 2) = rdrOLEDB.Item(2).ToString
Next
' CboFormat.Items.Add()
' CboDayTime.Items.Add()
' CboLocation.Items.Add()
' CboName.Items.Add()
End While
End Using
End Using
End Using
For z As Integer = 0 To 35
CboCourse.Items.Insert(z, CourseArray(z, 0).ToString)
Next
End Sub
结束班
你可以猜到这是我一直在努力的代码。 如果我想尽力做的话,任何帮助都会很棒。
答案 0 :(得分:0)
每次读取数据源中的记录时,都会运行0到35循环。
While rdrOLEDB.Read
Dim l As Integer
For l = 0 To 35
'cmdOleDB.Parameters.Add("@row", OleDbType.VarWChar).Value = l
CourseArray(l, 0) = rdrOLEDB.Item(0).ToString
CourseArray(l, 1) = rdrOLEDB.Item(1).ToString
CourseArray(l, 2) = rdrOLEDB.Item(2).ToString
Next
Name.Items.Add()
End While