Solved

ASP.net get data from a data connection or GridView

Posted on 2011-03-23
4
531 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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:murbro
ID: 35197067
How do I do that
0
 
LVL 1

Accepted Solution

by:
Muralidharand earned 500 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:murbro
ID: 35197169
thanks very much
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 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