Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
VB
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
Posted
Updated 25-Jun-13 3:42am
v3
Comments
[no name] 25-Jun-13 9:04am    
"how i can do this", how you can do what? Write a SELECT statement that selects the data you want to display.
yogeshrrc 25-Jun-13 9:25am    
sir , i am unable to display records in table.
[no name] 25-Jun-13 9:31am    
Well why not? You assume that we can see your code or read your mind to know what it is that you have tried to do and what the actual problem is.
yogeshrrc 25-Jun-13 9:38am    
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




And I also Try this


Try
con.Open()
Dim da As New SqlDataAdapter()
Dim ds As New DataSet
da = New SqlDataAdapter(s, con)
da.Fill(ds, "aa")
Dim tblviewEnq As DataTable
tblviewEnq = ds.Tables(0)
GridView1.DataSource = ds.Tables("aa")
Catch ex As Exception
lblerror.ForeColor = Drawing.Color.Red
lblerror.Text = ex.Message.ToString
End Try


[no name] 25-Jun-13 10:21am    
I would suggest that you go through this, http://www.aspnet101.com/2007/11/a-beginners-guide-to-the-gridview/, instead of trying code that would never work for a web page.

1 solution

There are two ways you can do this, depending on your needs.

1. Use the GridView control with a SqlDataProvider. 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 using StringBuilder. Once you have appended the final </table>, give its string value to a Literal placeholder.

There are lots of examples for these techniques on the web.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900