GridView with a View

  • Thread starter Thread starter =?ISO-8859-1?Q?Mika=EBl_PLOUHINEC?=
  • Start date Start date
?

=?ISO-8859-1?Q?Mika=EBl_PLOUHINEC?=

Hello,

I work with SQL Server 2005 and a dataset in my VS.NET project. I would
like to use a GridView. Is that possible to use a grid View and
configure his datasource with a View (in SQL Server)?

How can I do that?

Thanks a lot.

Mike
 
Here is a code sample of how to create a dataset and populate the
gridview

DataSet myDataSet = new DataSet("ds1");
string sql = "Select * from Customer";
SqlConnection myConnection = new SqlConnection(@"Data
Source=MYSqlDB;Integrated Security=SSPI;"Initial Catalog=Northwind");
SqlCommand cmd1 = new SqlCommand(sql);
cmd1.CommandType = CommandType.Text;
myConnection.Open();
cmd1.Connection = myConnection;
SqlDataAdapter sqlDAdapt = new SqlDataAdapter();
sqlDAdapt.SelectCommand=cmd1;
sqlDAdapt.Fill(myDataSet,"Account");
myGridView.DataSource = myDataSet.Tables[0];

Let me know if you have any questions
+
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top