我是vb.net的新手,我已经将数据从数据库显示到文本框中,如果搜索的结果只显示了最后一条记录的问题,我想在该文本框中使用向下键来探索所有数据。谢谢;;
con = New SqlConnection(cs)
con.Open()
Dim sql As String = " Select RTRIM(visit.regdate),RTRIM(Patientno) from visit where visit.accno =@d6 "
cmd = New SqlCommand(sql, con)
cmd.Parameters.AddWithValue("d6", accno.Text)
rdr = cmd.ExecuteReader()
While (rdr.Read() = True)
regdate.Value = rdr.GetValue(0)
patientno.Text = rdr.GetValue(1)
End While
答案 0 :(得分:0)
显示数据用于使用数据表控件的更好方法之一。它使用起来非常简单。使用Datatable控件,您可以显示要显示的所有记录,但添加了代码,还可以更新,删除,过滤和搜索。
using cmd as new sqlcommand("sql string",sqlconnection)
cmd.parameter.add(new sqlparameter("@parameter",parametervalue))
'Then create a Sql data adapter and data table variable
Dim myAdapter as new Sqldataadapter(cmd)
Dim dt as new Datatable
'fill the datatable variable, best to catch it in a try catch statement
try
myAdapter.Fill(dt)
catch ex as exception
throw new exception(ex.tostring)
end try
'then assign the tables datasource, with the recently filled datatable
DatatableControl.Datasource = dt
'end using statment
End Using