You must Sign In to post a response.
  • Category: .NET

    How to retrieve data from database and display in gridview?

    Are you looking for information on data binding? Want to know how to retrieve data from database and display in gridview? Read this thread to learn more about gridview with examples.

    Hi friends,
    I was design single form in window application, in that form I have 1 texbox and 1 gridview.
    Now my query is when I enter day value in textbox that value should be retrive from database and display in gridview...
  • #722575
    You can use AutoComplete using JQUERY and AJAX.

    Imran Ansari
    Sr. Software Engineer
    Gtalk: imranbluffy
    Yahoo: imranonline2
    My Personal blog:

  • #722582
    Hi navaneethakrishnan,

    This is related to searching option. You just write SP for that and based on textbox value you just bind your grid.

    select * from table where search_field like '%'+@seacrh+'%'

    and pass that textbox value as a parameter when you bind your grid.

    protected void txtDwg_TextChanged(object sender, EventArgs e)
    gdDocument.CurrentPageIndex = 0;
    protected void Bind_Document()
    Design objDocument = new Design();
    DataSet dsDocument = new DataSet();
    string SED_Code = ddlFunctionalUnit.SelectedItem.ToString();
    string Dwg_No = txtDwg.Text.Trim().Replace(" ", "");
    if (SED_Code == "--All--")

    dsDocument = objDocument.Get_ALL_Drawing_Schedule_MMHW("FETCH", Proj_Code, ddlDiscipline.SelectedValue, "",Dwg_No);
    dsDocument = objDocument.Get_ALL_Drawing_Schedule_MMHW("FETCH", Proj_Code, ddlDiscipline.SelectedValue, SED_Code,Dwg_No);
    ViewState["dsDocument"] = dsDocument;
    gdDocument.DataSource = dsDocument;

    This is sample code for your reference modify the code appropriate to your requirement.

    Hope this information is helpful to you..

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #722771

    try like this code

    sing System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    namespace retrieveData
    public partial class Form1 : Form
    SqlConnection sqlcon = new SqlConnection(ConfigurationManager.AppSettings["constr"]);
    SqlCommand sqlcmd = new SqlCommand();
    SqlDataAdapter da = new SqlDataAdapter();
    DataSet ds = new DataSet();

    public Form1()
    private void Form1_Load(object sender, EventArgs e)
    sqlcmd = new SqlCommand("select * from emp where joindate='" + txtJdate.Text + "'", sqlcon);
    da = new SqlDataAdapter(sqlcmd);

    Your Hard work never fails

  • #727244

    I've given an example of code snippet for binding data to gridview.

    private void GetStudentInfoToGridView(string StdntID)
    string constring = "Data Source=LPT02DHK;Initial Catalog=dbStudent;Persist Security Info=True;User ID=sa;Password=123";
    string qryStudent = "SELECT * FROM StudentInfo WHERE StudntID='"+StdntID+"'";
    SqlConnection cnStudent = new SqlConnection(constring);
    SqlCommand cmdStudent = new SqlCommand(qryStudent, cnStudent);
    SqlDataAdapter sdaStudent = new SqlDataAdapter(cmdStudent);
    DataSet dsStudent = new DataSet();
    sdaStudent.Fill(dsStudent, "StudentInfo");
    GridView1.DataSource = dsStudent;

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    if (e.Row.RowType == DataControlRowType.DataRow)
    StudentInfo entry = e.Row.DataItem as StudentInfo;
    e.Row.Cells[0].Text = Convert.ToString(entry.StudentID);
    e.Row.Cells[1].Text = entry.Name;
    e.Row.Cells[2].Text = entry.Semester;
    e.Row.Cells[3].Text = entry.Class;

    Best regards

  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.