Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 12th, 2006, 07:18 AM
Authorized User
 
Join Date: Jan 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default gridview

 Dim DBConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:/Inetpub/wwwroot/newfolder/BooksDB.mdb")
        DBConnection.Open()

        '-- Issue an SQL command through the database connection
        Dim SQLString As String
        SQLString = "SELECT BookID, BookType, BookTitle, BookPrice, BookQty " & _
                    "FROM Books ORDER BY BookID"
        Dim DBCommand = New OleDbCommand(SQLString, DBConnection)

        '-- Retrieve a recordset of selected records from the database
        Dim DBReader = DBCommand.ExecuteReader()

        '-- Bind data reader to GridView control
        BookGrid.DataSource = DBReader
        BookGrid.DataBind()


this code works fine , but when i use sqldatareader it isnt working.below is my code .just tell me wats wrong.both are done on buttons click event


  Dim sqlconnection As New SqlConnection("Data Source=GWSHJ;Initial Catalog=Northwind;User ID=sa;Password=EkLi05SQLgws")
        Dim cmd = New SqlCommand("SELECT CategoryID, CategoryName, Description FROM Categories", sqlconnection)
        ' cmd.CommandType = Data.CommandType.Text
        Try
            sqlconnection.Open()
             Dim reader As SqlDataReader()
            reader = cmd.ExecuteReader() GridView1.DataSource = reader
            GridView1.DataBind()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try


 
Old December 26th, 2006, 08:45 AM
Authorized User
 
Join Date: Dec 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Sunnys Send a message via Yahoo to Sunnys
Default

hi
 ur code is right
ru using the same line
 Dim cmd = New SqlCommand("SELECT CategoryID, CategoryName, Description FROM Categories", sqlconnection)
then try
dim cmd as sqlCommand=New SqlCommand("SELECT CategoryID, CategoryName, Description FROM Categories")
cmd.connection=sqlconnection

may this help
 
Old December 26th, 2006, 09:00 AM
Authorized User
 
Join Date: Jan 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks,
if u no this answer.can u tel me.

Hi

protected WebApplication2.dsGrd dsGrd;

if (Session["GridDataSet"].ToString() != "NEW")
            {

                dsGrd = (WebApplication2.dsGrd) Session["GridDataSet"];

            }
            else
                dsGrd= new WebApplication2.dsGrd();


this was done in asp.net 1.1.
i want the same to be done in 2.0 how to do it.and if possible write the code in vb.net.How do you call the dataset in asp.net 2.0.ive created an xsd schema called dsGrd.or shud we use table adapetr for this.im very confused.pls tell me.








Similar Threads
Thread Thread Starter Forum Replies Last Post
Get GridView Cell Value Based on GridView Column stublair C# 2008 aka C# 3.0 0 September 4th, 2008 08:30 AM
Gridview user007 ASP.NET 2.0 Basics 2 June 22nd, 2008 09:30 AM
Gridview Thinlizzy ASP.NET 2.0 Basics 2 July 20th, 2007 08:33 AM
GridView Sheraz Khan ASP.NET 2.0 Basics 1 July 19th, 2007 10:28 AM
GridView heba ASP.NET 2.0 Professional 0 May 28th, 2007 01:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.