Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
2.20/5 (3 votes)
See more:
I want to show records in database with datagridview. how can I do?
Posted
Comments
Ajith K Gatty 23-Jul-14 6:50am    
hello brother,
You should Google for this. You will get good solutions.
goksurahsan 23-Jul-14 7:52am    
thank you but ı did this
Prakriti Goyal 23-Jul-14 6:51am    
use Gridview.DataSource = <datasource>;
Gridview.DataBind();
goksurahsan 23-Jul-14 7:53am    
I can't use .Data.Bind();
Prakriti Goyal 23-Jul-14 7:59am    
Why can't you use it. Please mention the problem you are facing or your code.

 
Share this answer
 
Comments
goksurahsan 23-Jul-14 7:00am    
I looked everything in google but i don't understand anything
It's very easy way to bind the data to GridView from Database. Please, write below code and you can bind data to GridView:

SqlConnection cnn = new SqlConnection("Data Source=HOTH;Initial Catalog=Chintan;User ID=sa;Password=123");
cnn.Open();
SqlDataAdapter da = new SqlDataAdapter("Select * from tbl_data", cnn);
DataSet ds = new DataSet();
da.Fill(ds);
cnn.Close();

if (ds.Tables[0].Rows.Count != 0)
{
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}


Thank You..... :-)
 
Share this answer
 
Comments
goksurahsan 23-Jul-14 7:15am    
thank you
goksurahsan 23-Jul-14 7:18am    
but ı can't use Data.Bind() :(
Chintan Desai1988 23-Jul-14 7:56am    
y u cn't be able to use dataBind() method tell me then helping to give solution from my side
goksurahsan 23-Jul-14 7:59am    
I don't understand you :(
Prakriti Goyal 23-Jul-14 8:01am    
its not Data.Bind() its DataBind()
SqlConnection con = new SqlConnection("Data Source=NONETF3SFRWS151;Initial Catalog=HealthPlus;User ID=sa;Password=sql");
            con.Open();
            SqlDataAdapter adp = new SqlDataAdapter("select * from login", con);
            DataSet ds = new DataSet();
            adp.Fill(ds);
            dataGridView1.DataSource = ds.Tables[0];
 
Share this answer
 
Comments
goksurahsan 23-Jul-14 8:22am    
thank you I did this but I want to show data and this didn't show data
Prakriti Goyal 23-Jul-14 8:23am    
http://tech.pro/tutorial/664/csharp-tutorial-binding-a-datagridview-to-a-database

Please go through this link because I think you are using Access as your database and SqlCommand, SqlConnection is for Sql server
goksurahsan 23-Jul-14 8:26am    
thank you
Prakriti Goyal 23-Jul-14 8:27am    
Is your query solved?
goksurahsan 23-Jul-14 8:30am    
yes

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