---
title: "The SelectCommand property has not been initialized before calling “Fill"  
description: "The SelectCommand property has not been initialized before calling “Fill"  
author: "Anonymous User"  
published: 2013-06-19  
updated: 2013-06-19  
canonical: https://www.mindstick.com/forum/1202/the-selectcommand-property-has-not-been-initialized-before-calling-fill  
category: "ado.net"  
tags: ["ado.net"]  
reading_time: 1 minute  

---

# The SelectCommand property has not been initialized before calling “Fill

Hi [Developers](https://www.mindstick.com/articles/12875/blunders-you-must-avoid-while-hiring-java-developers-to-get-the-best-fulfilling-your-needs),\
The SelectCommand property has not been initialized before calling “Fill\
My line of code as following\
**[SqlConnection](https://www.mindstick.com/forum/1209/sqlconnection-sqlcommand-sqldatareader-idisposable) cn = new SqlConnection("[Data Source](https://www.mindstick.com/interview/808/what-is-a-data-source)=.\SQLEXPRESS;AttachDbFilename=C:\Users\MANTHAN\[Documents](https://www.mindstick.com/articles/156931/the-main-types-of-business-documents)\[Visual Studio](https://www.mindstick.com/articles/12378/visual-studio-for-mac-is-out-of-beta-preview-now-officially-available) 2010\WebSites\sample\App_Data\Database.mdf;[Integrated Security](https://www.mindstick.com/forum/159040/what-is-the-difference-between-integrated-security-true-and-integrated-security-sspi)=True;User Instance=True");** **[SqlCommand](https://www.mindstick.com/forum/91/difference-between-sqlcommand-and-sqlcommandbuilder) cmd = new SqlCommand("SELECT * FROM stu1", cn);** **[SqlDataAdapter](https://www.mindstick.com/interview/33991/what-is-sqldataadapter) adp = new SqlDataAdapter(cmd);****\** **DataSet ds = new DataSet();****\** **adp.Fill(ds);****\** **GridView1.DataSource = ds.Tables[0];**

## Replies

### Reply by Anonymous User

Hi,\
adp.fill(ds); will take care of every thing.**Remove cmd.ExecuteNonQuery();.**\
try as following\
**try****{** **SqlConnection cn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Users\\MANTHAN\\Documents\\Visual Studio 2010\\WebSites\\sample\\App_Data\\Database.mdf;[Integrated](https://www.mindstick.com/forum/33532/handler-pagehandlerfactory-integrated-has-a-bad-module-managedpipelinehandler-in-its-module-list) [Security](https://www.mindstick.com/articles/43813/new-security-technologies)=True;User Instance=True");****\** **SqlCommand cmd = new SqlCommand("SELECT * FROM stu1", cn);** **SqlDataAdapter adp = new SqlDataAdapter(cmd);****\** **//cmd.Executenonquery(); removed****\** **DataSet ds = new DataSet();****\** **adp.Fill(ds);****\** **GridView1.DataSource = ds.Tables[0];****}****\** **catch(exception ex)** **{** **Messagebox.show(ex.Message);** **}****\**I hope it helpful for you.


---

Original Source: https://www.mindstick.com/forum/1202/the-selectcommand-property-has-not-been-initialized-before-calling-fill

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
