Sample code:
Try
            Dim constr As String = ConfigurationManager.ConnectionStrings("FileDBConnectionString").ConnectionString
            Using con As New SqlConnection(constr)
                Using cmd As New SqlCommand()
                    'cmd.CommandText = "SELECT fldControlno, fldRecno, fldFileName ,fldDate FROM tblPDSTrainzATemp where fldRecno= ('" & txtrecordno.Text & "')" Convert(varchar, fldDate, 101)
                    ' 
                    cmd.CommandText = "SELECT fldcontrolno,fldEmpID,Convert(varchar, fldDate, 101) as [Date],fldPosition, fldSalary, fldAttachType, fldfilename,fldfiletype,fldfiledata FROM tblCOS"
                    cmd.Connection = con
                    con.Open()
                    GridCOS.DataSource = cmd.ExecuteReader()
                    GridCOS.DataBind()
                    con.Close()
                End Using
            End Using

        Catch ex As Exception
            'Session.Add("ErrorMessage", ex.Message)
            'Response.Redirect("~/errorpage.aspx")
            MsgBox(ex.Message)
        End Try

Don't dump code. Explain the problem.

Try This,

string strConnString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    using (SqlConnection con = new SqlConnection(strConnString))
    {
        using (SqlCommand cmd = new SqlCommand())
        {
            cmd.CommandText = "select top 10 * from Customers";
            cmd.Connection = con;
            con.Open();
            GridView1.DataSource = cmd.ExecuteReader();
            GridView1.DataBind();
            con.Close();
        }
    }

Hi,
Please be specific what problem you are facing and in which line of code
Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.