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 GaradRank #191 · 12.8K reputationPosted Jan 23, 2012, 1:46 AM EST
//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();
Satyapriya NayakRank #47 · 31.5K reputationPosted Jan 23, 2012, 1:45 AM EST
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
arun prasath94 reputationPosted Jan 23, 2012, 2:15 AM EST
arun prasath94 reputationPosted Jan 23, 2012, 3:36 AM EST
Krishna GaradRank #191 · 12.8K reputationPosted Jan 23, 2012, 3:42 AM EST
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 prasath94 reputationPosted Jan 23, 2012, 4:13 AM EST
arun prasath94 reputationPosted Jan 23, 2012, 4:14 AM EST
Krishna GaradRank #191 · 12.8K reputationPosted Jan 23, 2012, 4:15 AM EST
arun prasath94 reputationPosted Jan 23, 2012, 4:21 AM EST
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 GaradRank #191 · 12.8K reputationPosted Jan 23, 2012, 4:25 AM EST
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 prasath94 reputationPosted Jan 23, 2012, 4:36 AM EST