Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
2.00/5 (4 votes)
See more:
i want to assign hole database row and column value into datagrid how can its possible?
Posted
Comments
bbirajdar 13-Sep-12 9:44am    
'hole' database? Are you serious ?

1 solution

C#
using System;
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 _Default : System.Web.UI.Page
{


    protected void Page_Load(object sender, EventArgs e)
    {
        string strSQLconnection = (@"Data Source=GRCPWS00051\MSSQLSERVER1;Initial Catalog=new;Integrated Security=True");

      SqlConnection sqlConnection = new SqlConnection(strSQLconnection);

      SqlCommand sqlCommand = new SqlCommand("select * from persons", sqlConnection);

  sqlConnection.Open();



     SqlDataReader reader = sqlCommand.ExecuteReader();



      GridView1.DataSource = reader;

      GridView1.DataBind();

    }


  }

u need to change ur data sourse accordingly an table name......
it works perfect


in aspxpage
ASP.NET
<asp gridview="" id="GridView1"  runat="server">

it works fine
 
Share this answer
 
v2
Comments
bbirajdar 13-Sep-12 9:51am    
Do you think has only one table in the database? The question says, that a 'database' is to be bound to gridview and not only a 'table'

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