.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ADO.Net >> Post New QuestionBookmark and Share Subscribe to Forum

I have problem in displaying database in data grid view

Posted By: Atulya     Posted Date: August 03, 2010    Points:2   Category :ADO.Net
So could u give me the code for how to display data stored in data base in data grid view

Responses
Author: Mallikarjuna Chigicherla             
Posted Date: August 03, 2010     Points: 5   

Add the name space
using system.data;
using system.data.sqlclient;


protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=ServerName;Initial Catalog=Test;User ID=sa;Password=123");
SqlDataAdapter da = new SqlDataAdapter("select * from Tablename", con);
DataSet ds = new DataSet();

Gridview1.DataSource = ds.Tables[0];
Gridview1.DataBind();

}


Thanks & Regards,
Mallikarjuna Chigicherla
Author: Syed Shakeer Hussain             
Posted Date: August 03, 2010     Points: 5   

Hi,
Use the below code

SqlDataAdapter da = new SqlDataAdapter("select * from Tablename", con);
DataSet ds = new DataSet();
da.Fill(ds,"Tablename");
Gridview1.DataSource = ds.Tables["Tablename"];
Gridview1.DataBind();


Author: BangaruBabuPureti             
Posted Date: August 03, 2010     Points: 5   
Author: Hiren Soni             
Posted Date: August 03, 2010     Points: 5   

SqlConnection con = new SqlConnection("Data Source=ServerName;Initial Catalog=Test;User ID=sa;Password=123");
SqlDataAdapter da = new SqlDataAdapter("select * from Tablename", con);
DataSet ds = new DataSet();
da.Fill(ds);
Gridview1.DataSource = ds.Tables[0];
Gridview1.DataBind();

Hiren soni
http://www.dotnetask.com
Author: Atulya             
Posted Date: August 05, 2010     Points: 5   

I hav use this code it is giving error in Databind the error message is
"Error 1 Non-invocable member 'System.Windows.Forms.Control.DataBindings' cannot be used like a method" .

Author: Syed Shakeer Hussain             
Posted Date: August 05, 2010     Points: 5   

Hi Atulya,

Can you send your Gridview Code how you had written...

Author: swathi             
Posted Date: August 11, 2010     Points: 5   

dim da as SqlDataAdapter
dim ds as dataset
Public Con As New SqlConnection("uid=sa;pwd=123;Database=databasename;Data Source=servername")
da = New SqlDataAdapter("select * from tablename", Con)
ds = New DataSet
da.Fill(ds)
datagridview1.datasource=ds.tables(0)

Regards
Swathi

Author: sriram             
Posted Date: October 28, 2011     Points: 20   

using System.Data.SqlClient;
using System.Data;
using System.Configuration

Web.Config:

<appsettings>
<add key="DSV" value="server=Servername;UID=username;PWD=password;DataBase=Databasename">
</appsettings>

Form1.aspx.cs:

string str=ConfigurationSettings.Appsettings["DSV"].ToString();
sqlconnection conn=new sqlconnection(str);
string sqlstr="select * from employee where empid='" + TextBox1.Text + "'";
sqlDataAdapter adp=new sqlDataadapter(sqlstr,conn);
Dataset ds=new Dataset();
adp.Fill(ds);
Gridview1.DataSource(ds);
GridView1.DataBind();

Hope this will help..
Let me know any Questoions

Regards
Sriram.R

www.databaseresource.blogspot.com



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend