Pages

Monday, December 26, 2011

Fill Dataset In Asp.net C#

Fill DataSet In Asp.net C#

Introduction :


In this article i will show how to fill dataset from database sql server using c# language .For this i have created common methodh in which you have just pass the query and it automatically return the filled dataset .GetDataSet function contains the easy code to fill the dataset .

Calling the method :
DataSet Ds = GetDataSet("Select * from Tablename");

Method to bind dataset :
private DataSet GetDataSet(string Query)
    {
        DataSet Ds = new DataSet();
        try
        {
            
            string strCon =""; // set connetion string here ..
            SqlConnection Con = new SqlConnection(strCon);
            SqlDataAdapter Da = new SqlDataAdapter(Query, Con);
            Da.Fill(Ds);
           
        }
        catch (Exception)
        {
        }
        return Ds;
    } 


Related Other posts