Click here to Skip to main content
15,924,829 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
send me the code to search a item which is given in textbox in a database
frontend asp.net
backend Sql server2008
IDE visual studio
Posted
Updated 24-Aug-11 22:39pm
v2
Comments
Prerak Patel 25-Aug-11 4:39am    
Not a question. Google it.
Smithers-Jones 25-Aug-11 4:57am    
Not a question (and demanding). Reported.

SQL
CREATE TABLE [dbo].[StateMaster](
	[StateIdfr] [bigint] IDENTITY(1,1) NOT NULL,
	[StateName] [varchar](50) NULL
) 


Write Code for Textbox and Button in Front End with a Grid



VB
Sub BindGrid()
        Dim dt As New DataTable
        dt = Obj.GetStateDetails(txtSearch.Text.Trim)
        If dt.Rows.Count > 0 Then

            dgdState.DataSource = dt
            dgdState.DataBind()

        Else
            lblMsg.Text = "No Records"
            dgdState.DataSource = Nothing
            dgdState.DataBind()
        End If
    End Sub

Call the Above Bindgrid function when Click Search Button

---

Function Class

VB
Public Function GetStateDetails(ByVal StateName As String) As DataTable

 Dim dt As New DataTable
        Dim da As New SqlDataAdapter("Select StateIdfr,StateName, from StateMaster where StateName='%" & StateName & "", Con)
        da.Fill(dt)
        Return dt

End Function
 
Share this answer
 
v3
We are not here to give you code.

You need to learn stuffs on Asp.net and Ado.net, you can start from these:

Using ADO.NET for beginners[^]

Beginners Introduction to ASP.NET[^]
 
Share this answer
 
protected void btnSearchGrid_Click(object sender, EventArgs e)
{
if (txtnamesearch.Text == "")
{
Label7.ForeColor = Color.Red;
Label7.Text = "Plz Enter SchoolName to Search";
}
else
{
string Mode = "G";
pr.Mode = Mode;
pr.SchoolName = txtnamesearch.Text;
dt = new DataTable();
dt = logic.GetAlldetails(pr);
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
Label7.ForeColor = Color.Green;
Label7.Text = "Searched Sucessfully";
}
else
{
string Mode1 = "G";
pr.Mode = Mode1;
pr.SchoolName = txtnamesearch.Text;
dt = new DataTable();
dt = logic.GetAlldetails(pr);
if (dt.Rows.Count == 0)
{
GridView1.DataSource = dt;
//GridView1.Dispose();
GridView1.DataBind();

}
Label7.ForeColor = Color.Red;
Label7.Text = "The Name Your Searching DoesNot Exist:::";
}
}
}


Try this Code

Bye
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900