Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
C#
private void btnView_Click(object sender, EventArgs e)
        {
            
            SqlDataAdapter da = new SqlDataAdapter("select * from view_SpareParts ", con);
            DataSet ds = new DataSet();
            da.Fill(ds, "ca");
            dataGridView1.Show();
        }
Posted
Updated 11-Aug-12 22:21pm
v2
Comments
Sergey Alexandrovich Kryukov 12-Aug-12 4:22am    
What "calling a view" supposed to mean? :-) It is not a method, function, procedure, property or operator...
--SA
Gilbertinino 12-Aug-12 4:24am    
i mean to display a content of a view from sql server 2005 in datagridview
Sergey Alexandrovich Kryukov 12-Aug-12 4:23am    
It looks like ADO.NET, but tag it.
--SA
Gilbertinino 12-Aug-12 4:25am    
how can i do it?
Sergey Alexandrovich Kryukov 12-Aug-12 12:13pm    
To change the tags, use "Improve question" above.
--SA

First of all, there no such concept as "call a view". Moreover, a database view does not exist for a client code, mode exactly, it is absolutely transparent to it. From a client perspective, a view behaves exactly like a table. Please see:
http://en.wikipedia.org/wiki/View_%28database%29[^].

And to show a table in DataGridView, you can use data binding. Please start here:
http://msdn.microsoft.com/en-us/library/k39d6s23.aspx[^],
http://msdn.microsoft.com/en-us/library/fbk67b6z.aspx[^] (binding is explained here).

—SA
 
Share this answer
 
v2
Comments
Mehdi Gholam 12-Aug-12 5:15am    
5'ed
Sergey Alexandrovich Kryukov 12-Aug-12 12:12pm    
Thank you, Mehdi.
--SA
Espen Harlinn 12-Aug-12 12:59pm    
5'ed!
Sergey Alexandrovich Kryukov 12-Aug-12 23:15pm    
Thank you, Espen.
--SA
You have to bind the grid view to your data :
C#
private void btnView_Click(object sender, EventArgs e)
        {
            
            SqlDataAdapter da = new SqlDataAdapter("select * from view_SpareParts ", con);
            DataSet ds = new DataSet();
            da.Fill(ds, "ca");

            dataGridView1.DataSource = ds.Table[0];
        }
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 12-Aug-12 4:30am    
Correct, my 5.
I also explained about views and provided some links, please see my answer.
--SA
Espen Harlinn 12-Aug-12 12:58pm    
Good reply :-D
Mehdi Gholam 12-Aug-12 13:08pm    
Thanks Espen!

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