Hi !
Now i want to show a entered filed from sql database, for Example student table contains name,address, and id, In textbox if i enter "name" means it display name filed from student table,
I am a beginner in Asp.Net, So please Help me to do this project.....
Thanks!
Regards!
G.Arun Prasath
Loading
Krishna GaradPosted Jan 23, 2012, 6:46 AM
//Connection and Command
SqlConnection cn=new SqlConnection("Your Connection String");
//pass the field name from textbox to command
SqlCommand cmd=new SqlCommand("Select"+textbox1.Text+" From Student ",cn);
//Create Dataset
DataSet ds=new DataSet();
//Call data addapeter to fill the dataset
SqlDataAdapter da=new SqlDataAtapter(cmd);
da.Fill(ds);
//Bind to Gridview
GridView1.DataSource=ds.Tables[0];
GridView1.DataBind();
arun prasathPosted Jan 23, 2012, 9:36 AM
Krishna GaradPosted Jan 23, 2012, 9:25 AM
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
//Page_Load
public partial class testsearch : System.Web.UI.Page
{
}
//Button Click Event
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection("Data Source=admin;Initial Catalog=detail;Integrated Security=True");
//pass the field name from textbox to command
SqlCommand cmd = new SqlCommand("Select" + TextBox1.Text + " From annauniversity ", cn);
//Create Dataset
DataSet ds = new DataSet();
//Call data addapeter to fill the dataset
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
//Bind to Gridview
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
arun prasathPosted Jan 23, 2012, 9:21 AM
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class testsearch : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection("Data Source=admin;Initial Catalog=detail;Integrated Security=True");
//pass the field name from textbox to command
SqlCommand cmd = new SqlCommand("Select" + TextBox1.Text + " From annauniversity ", cn);
//Create Dataset
DataSet ds = new DataSet();
//Call data addapeter to fill the dataset
SqlDataAdapter da = new SqlDataAtapter(cmd);
da.Fill(ds);
//Bind to Gridview
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
}
Krishna GaradPosted Jan 23, 2012, 9:15 AM
arun prasathPosted Jan 23, 2012, 9:14 AM
arun prasathPosted Jan 23, 2012, 9:13 AM
Krishna GaradPosted Jan 23, 2012, 8:42 AM
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection cn=new SqlConnection("Your Connection String");
//pass the field name from textbox to command
SqlCommand cmd=new SqlCommand("Select"+textbox1.Text+" From Student ",cn);
//Create Dataset
DataSet ds=new DataSet();
//Call data addapeter to fill the dataset
SqlDataAdapter da=new SqlDataAtapter(cmd);
da.Fill(ds);
//Bind to Gridview
GridView1.DataSource=ds.Tables[0];
GridView1.DataBind();
}
and on your source page
arun prasathPosted Jan 23, 2012, 8:36 AM
arun prasathPosted Jan 23, 2012, 7:15 AM
Satyapriya NayakPosted Jan 23, 2012, 6:45 AM
You question is not clear.As per my understanding you need perhaves when you write name in the textbox all records related to this name field you want to fetch.
Try this...
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlDataAdapter ad = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter sqlda;
DataSet ds;
string str;
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
str = "select * from student where name = '" + TextBox1.Text + "'";
cmd = new SqlCommand(str, conn);
sqlda = new SqlDataAdapter(cmd);
ds = new DataSet();
sqlda.Fill(ds, "student");
conn.Close();
GridView1.DataSource = ds;
GridView1.DataMember = "student";
GridView1.DataBind();
}
}
}
Thanks