Solved

ASP.net get data from a data connection or GridView

Posted on 2011-03-23
4
521 Views
Last Modified: 2012-08-13
Hi

I am using the following VB code to populate a GridView in ASP.net.
I need the user of my website to be able to use this data. How do I read the data
off the GridView using VB code?
Protected Sub Button_SeeWholeCalendar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button_SeeWholeCalendar.Click
        '// define a connection to the database
        Dim cs As String = ConfigurationManager.ConnectionStrings("WhatEverNameYouWant").ConnectionString
        cs = cs.Replace("App_Data\GC.accdb", Server.MapPath("App_Data\GC.accdb"))

        Dim cn As New OleDbConnection(cs)

        '// define the sql statement to execute
        Dim cmd As New OleDbCommand("SELECT * FROM [Table1]", cn)

        Try

            '// open the connection
            cn.Open()

            '// execute the sql statement
            Using reader As OleDbDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)

                ' While reader.Read()
                '// this loops through all of the returned records
                'Response.Write("blah")
                'End While

                GridView1.DataSource = reader
                GridView1.DataBind()

            End Using


        Catch ex As Exception
            Response.Write(ex.Message)

        Finally
            If cn.State <> ConnectionState.Closed Then
                cn.Close()
            End If
        End Try
    End Sub

Open in new window

0
Comment
Question by:murbro
  • 2
  • 2
4 Comments
 
LVL 1

Expert Comment

by:Muralidharand
Comment Utility
use the EditItem template to read the modified data .....
0
 

Author Comment

by:murbro
Comment Utility
How do I do that
0
 
LVL 1

Accepted Solution

by:
Muralidharand earned 500 total points
Comment Utility

Just add a new GridView to the page and, from its Smart Tag, click the Enable Editing checkbox (see attached imge ). This will add a CommandField to the GridView with an Edit button.

http://msdn.microsoft.com/en-us/library/ms972948.aspx

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.templatefield.edititemtemplate.aspx

http://programming.top54u.com/Samples/ASP-Net-cs/GridView-Control/GridView-Edit-Update-Cancel-Commands/Default.aspx
0
 

Author Closing Comment

by:murbro
Comment Utility
thanks very much
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now