如何从数据库中选择信息并将其加载到水晶报告中
我正在建立一个学校管理系统。我希望用户在文本框中键入特定名称,以将学生的考试记录显示在Crystal Report中。
但是我的代码无效。
我尝试过:
尝试
Sql =select * from Student where Fullname ='& txtname.Text&'
Connect()
cmd =新的OleDbCommand(Sql,con)
dr = cmd。 ExecuteReader()
当dr.Read
CrystalReportViewer1.Rows.Add
结束时
Catch ex As Exception
结束尝试
I am creating a school management system. And I want user to type a particular name in a textbox to display the student's exams records into the Crystal Report.
But my code isn't working.
What I have tried:
Try
Sql = "select * from Student where Fullname = '" & txtname.Text &'""
Connect()
cmd = New OleDbCommand (Sql,con)
dr = cmd. ExecuteReader ()
While dr.Read
CrystalReportViewer1.Rows.Add
End while
Catch ex As Exception
End Try
您的代码只是添加了行CrystalReportViewer1,它不会向添加的行添加任何数据,因此您可以从数据库中为每条记录获取一个空行。
Your code just adds rows to the CrystalReportViewer1, it does not add any data to the added row so you get a blank row for each record from the database.