从sql server表读取记录并显示在页面上的表中 [英] Read records from sql server table and display in table on the page
本文介绍了从sql server表读取记录并显示在页面上的表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有,
我想在sql server表的asp页面上的表中显示记录我必须说我在我的数据库表中有25个字段或列和100个记录,我想只选择一些列并在asp页面上以表格的形式显示所有这些列记录
i all ready created命令同样的
请告诉我,用简单的例子,我该怎么做
谢谢
问候
Yogesh
从下面的评论中复制的其他信息
dear All,
I wants to show records on in the table on the asp page from sql server table i must say that i have 25 field or columns and 100 record in my database table and i wants to select only some columns and display all these columns records in the form of a table on the asp page
i all ready created command for the same
plz let me know, with the simple example , how i can do this
thanks
regards
Yogesh
additional information copied from comment below
Dim ss As String = "select Enquiry_No, Enquiry_date, Name, DOB, Father_Name, Mother_Name, Parents_Contact, Center_Name, Course, Class, Subject FROM([EIMS].[dbo].[Enquiry] "
Try
con.Open()
Dim da As New SqlDataAdapter()
Dim ds As New DataSet
da = New SqlDataAdapter(ss, con)
da.Fill(ds, "aa")
Dim tblviewEnq As DataTable
tblviewEnq = ds.Tables(0)
Dim drCurrent As DataRow
For Each drCurrent In tblviewEnq.Rows
Console.WriteLine("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10}",
drCurrent("Enq.NO").ToString,
drCurrent("Enquiry Date").ToString,
drCurrent("Name").ToString,
drCurrent("DOB").ToString,
drCurrent("Father's Name").ToString,
drCurrent("Mother's Name").ToString,
drCurrent("Parent's Contact").ToString,
drCurrent("Center").ToString,
drCurrent("Course").ToString,
drCurrent("Class").ToString,
drCurrent("Subject").ToString)
Next
Console.ReadLine()
Catch ex As Exception
lblerror.ForeColor = Drawing.Color.Red
lblerror.Text = ex.Message.ToString
End Try
推荐答案
有两种方法可以o这取决于您的需求。
1.使用GridView
控件,并带有的SqlDataProvider
。将网格设置为不自动生成列,然后定义要显示的列。这是非常灵活的,允许分页你的数据,但设置和格式可能很棘手。
2.使用查询检索页面时的数据正在组装并使用StringBuilder
手动构建HTML表。添加最终< / table>
后,将其字符串值提供给Literal
占位符。
网上有很多这些技术的例子。
There are two ways you can do this, depending on your needs.
1. Use theGridView
control with aSqlDataProvider
. Set the grid to not auto-generate columns, and then define the columns you want to display. This is very flexible and allows for paging your data, but can be tricky to set up and format.
2. Use a query to retrieve your data when the page is being assembled and manually build an HTML table usingStringBuilder
. Once you have appended the final</table>
, give its string value to aLiteral
placeholder.
There are lots of examples for these techniques on the web.
这篇关于从sql server表读取记录并显示在页面上的表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文