0
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
4
Contributors
3
Replies
15
Views
2 Years
Discussion Span
Last Post by zinist
0

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();
        }
    }
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.