【发布时间】:2016-01-03 14:54:55
【问题描述】:
我有一个存储过程,我想将记录显示到combobox。但它说
此行的位置 0 处没有行。
cboSchoolYear.Text = (dt.Rows(0)("Schoolyear"))
存储过程代码:
ALTER PROCEDURE [dbo].[uspLatestDateEnrolled]
-- Add the parameters for the stored procedure here
@studID INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT TOP 1 DateEnrolled as LatestDate,
SchoolYear,Levels,Section,StudentID
FROM StudentHistory
WHERE studentID = @studID
ORDER BY DateEnrolled DESC
END
vb.net代码
cn.Open()
Using cmd As New SqlClient.SqlCommand("uspLatestDateEnrolled", cn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add(New SqlParameter("@studID", frmView.dgv1.SelectedCells(0).Value))
cboSchoolYear.Text = (dt.Rows(0)("Schoolyear"))
cboGradeLevel.Text = (dt.Rows(1)("levels"))
cboSection.Text = (dt.Rows(2)("Section"))
dtpEnrollment.Text = (dt.Rows(3)("dateEnrolled"))
End Using
cn.Close()
【问题讨论】:
-
添加参数后,您不会执行填充数据表的命令。除此之外 dt 在哪里声明?您需要在尝试使用它之前填写它......另外,您正在执行 top1 这意味着您将获得 0 或 1 行而不是 2、3 等等,但您正在尝试将文本设置为永远不会回来的记录。 ..
标签: sql-server vb.net sql-server-2008 combobox