Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ASP.net get data from a data connection or GridView

Posted on 2011-03-23
4
Medium Priority
?
537 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:Murray Brown
  • 2
  • 2
4 Comments
 
LVL 1

Expert Comment

by:Muralidharand
ID: 35197063
use the EditItem template to read the modified data .....
0
 

Author Comment

by:Murray Brown
ID: 35197067
How do I do that
0
 
LVL 1

Accepted Solution

by:
Muralidharand earned 2000 total points
ID: 35197131

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:Murray Brown
ID: 35197169
thanks very much
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Loops Section Overview
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

916 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