---
title: "Coding issue"  
description: "Coding issue"  
author: "Ajay Kembale"  
published: 2015-06-16  
updated: 2015-06-17  
canonical: https://www.mindstick.com/forum/23298/coding-issue  
category: "c#"  
tags: ["database connection"]  
reading_time: 1 minute  

---

# Coding issue

```
 Protected
void BindGridview() { using(SqlConnection conn = new SqlConnection("Data
Source=abc;Integrated Security=true;Initial Catalog=Test")) { con.Open(); SqlCommand cmd =new SqlCommand("Select
UserName, First Name,LastName,Location FROM Users", conn); SqlDataReader sdr =cmd.ExecuteReader(); gvUserInfo.DataSource = sdr; gvUserInfo.DataBind(); conn.Close(); } }
```

\

Its [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) I was [trying](https://answers.mindstick.com/qa/93698/6-mistakes-couples-are-trying-to-save-money) found on [google](https://www.mindstick.com/articles/43833/google-lighthouse-and-how-is-it-changing-the-way-we-development-and-design-websites), what is 'using' here and \
'gvUserInfo' [please explain](https://www.mindstick.com/forum/344/hi-rohith-i-am-new-for-mvc-please-explain-how-to-set-implicitly-isauthenticated-true) I am started with C# [basics](https://www.mindstick.com/articles/157133/tips-to-learn-excel-the-basics) recently\

## Replies

### Reply by Sunil Singh

Try like this.

```
Protected void BindGridview()
{
DataTable dt = new DataTable();
  using (SqlConnection conn = new SqlConnection("Data Source=abc;Integrated Security=true;Initial Catalog=Test"))
{
conn.Open();
                SqlCommand cmd = new SqlCommand("Select UserName, First Name,LastName,Location FROM Users", conn);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(dt);
                gvUserInfo.DataSource = dt;
gvUserInfo.DataBind();
                conn.Close();
}
}
```

\


---

Original Source: https://www.mindstick.com/forum/23298/coding-issue

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
