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

You are currently viewing the ASP.NET 3.5 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 July 7th, 2008, 01:21 PM
Registered User
 
Join Date: Jul 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default [HELP] Problems in Asp.net vb, database

appreciate whoever reply :)

Hi people, I would like to seek for some help in this piece of database searching.
I am using Visual Studio 2008, Vb languages

This is my old version of vb coding behind page.
as below.
Code:
Namespace DBSearchSample
    Public Partial Class _Default
        Inherits System.Web.UI.Page
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            If Not IsPostBack Then
                btnSearch_Click(Me, Nothing)
            End If
        End Sub

        Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As EventArgs)
            Dim conn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True")

            conn.Open()

            ' 1. create a command object identifying
            ' the stored procedure
            Dim cmd As New SqlCommand("searchBooks", conn)

            ' 2. set the command object so it knows
            ' to execute a stored procedure
            cmd.CommandType = CommandType.StoredProcedure

            ' 3. add parameter to command, which
            ' will be passed to the stored procedure
            Dim author As String = tbAuthor.Text
            If author = "" Then
                author = Nothing
            End If
            Dim title As String = tbTitle.Text
            If title = "" Then
                title = Nothing
            End If
            Dim publisher As String = tbPublisher.Text
            If publisher = "" Then
                publisher = Nothing
            End If
            cmd.Parameters.Add(New SqlParameter("@author", author))
            cmd.Parameters.Add(New SqlParameter("@title", title))
            cmd.Parameters.Add(New SqlParameter("@publisher", publisher))

            GridView1.DataSource = cmd.ExecuteReader()
            GridView1.AutoGenerateColumns = True
            GridView1.DataBind()

            conn.Close()
        End Sub
    End Class
End Namespace
New version of coding behind page.
as below.

Code:
Namespace TestBook
    Partial Public Class _Default
        Inherits System.Web.UI.Page
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            If Not IsPostBack Then
                btnSearch_Click(Me, Nothing)
            End If
        End Sub

        Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As EventArgs)

            Dim connection As New Data.SqlClient.SqlConnection("Data Source=D:\Documents and Settings\Niel\Desktop\TestBook\Database1.mdf;Integrated Security=True;User Instance=True")

            connection.Open()

            ' 1. create a command object identifying
            ' the stored procedure
            Dim cmd As New Data.SqlClient.SqlCommand("searchBooks", connection)

            ' 2. set the command object so it knows
            ' to execute a stored procedure
            cmd.CommandType = data.CommandType.StoredProcedure

            ' 3. add parameter to command, which
            ' will be passed to the stored procedure
            Dim author As String = tbAuthor.Text
            If author = "" Then
                author = Nothing
            End If
            Dim title As String = tbTitle.Text
            If title = "" Then
                title = Nothing
            End If
            Dim publisher As String = tbPublisher.Text
            If publisher = "" Then
                publisher = Nothing
            End If
            cmd.Parameters.Add(New Data.SqlClient.SqlParameter("@author", author))
            cmd.Parameters.Add(New Data.SqlClient.SqlParameter("@title", title))
            cmd.Parameters.Add(New Data.SqlClient.SqlParameter("@publisher", publisher))

            GridView1.DataSource = cmd.ExecuteReader()
            GridView1.AutoGenerateColumns = True
            GridView1.DataBind()

            connection.Close()
        End Sub
    End Class
End Namespace
I would like to have a solution on displaying result in my grid view. Please lead me to a right way. Thanks
below is a ss of my design view:)

http://img183.imageshack.us/img183/9884/1223e21aa2.png

 
Old July 7th, 2008, 03:37 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You could do yourself a big favor and increase the chances on a useful answer by telling us what exactly the problem is.

Right now, all you do is post old and new code without telling us what the problem is, or what the differences between old and new are and why this is relevant.

I have no intention to play hide and seek, and I am pretty sure other board members feel the same.

Good questions == good answers.
Bad questions == being ignored, or getting answers like this one.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
 
Old July 7th, 2008, 05:39 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Only difference I saw was in the connection string to the DB.

The second one is pointing to a local directory on the development computer. So it can't possibly work anyplace except on that computer.

No idea of course if that is the problem you are having.

As Imar said, you didn't bother to tell us what is wrong.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving Images in SQL database using VB ASP.Net louie001 ASP.NET 1.0 and 1.1 Basics 1 November 24th, 2005 04:05 PM
Problems at Using CRViewer for Web-Forms (VB.NET) vblover Crystal Reports 1 August 27th, 2004 10:38 AM
Problems at Using CRViewer for Web-Forms (VB.NET) vblover BOOK: Professional Crystal Reports for VS.NET 0 August 18th, 2004 10:04 AM
problems with my vb.net code zanee VS.NET 2002/2003 0 October 10th, 2003 07:09 AM
VB.NET Edition code problems Solved charul_shukla BOOK: ASP.NET Website Programming Problem-Design-Solution 5 July 11th, 2003 01:56 AM





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