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