Sunday, January 24, 2010

Fill Dataset with StoredProcedure ASP.NET C#

GridView DataBind with Dataset

GridView Fill Dataset with StoredProcedure ASP.NET C#

===========================================================

DataSet MyQueryMethod(string sqlQueryString)

{

DataSet ds = new DataSet();

System.Data.SqlClient.

SqlConnection sqlConnection = new System.Data.SqlClient. SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString" ].ConnectionString);

System.Data.SqlClient.

SqlDataAdapter dataAdapter = new System.Data.SqlClient. SqlDataAdapter();

System.Data.SqlClient.

SqlCommand select = new System.Data.SqlClient. SqlCommand(sqlQueryString);

select.CommandType =

CommandType.StoredProcedure;

select.Connection = sqlConnection;

select.Parameters.Add(

"@startdate", SqlDbType.DateTime).Value = TextBox1.Text;

select.Parameters.AddWithValue(

"@enddate", SqlDbType.DateTime).Value = TextBox2.Text ;

dataAdapter.SelectCommand = select;

dataAdapter.Fill(ds);

return ds;

}


===========================================


on Load event for call the function


GridView1.DataSource = MyQueryMethod("BrowseUserCharge");

GridView1.DataBind();

4 comments:

  1. please asma tell me.
    i have drag to stored proc on data set 1st name rb and 2nd name is finalbal and i drag all record from dataset to report.rdlc and i drag microsoft report viewer on form and back i wrote this code

    DataSet2.rbDataTable data = new DataSet2.rbDataTable();
    DataSet2TableAdapters.rbTableAdapter adt = new DataSet2TableAdapters.rbTableAdapter();

    adt.Fill(data, 1);

    ReportDataSource rds = new ReportDataSource("DataSet2_rb", data);
    ReportViewer1.LocalReport.DataSources.Clear();
    ReportViewer1.LocalReport.DataSources.Add(rds);
    ReportViewer1.LocalReport.Refresh();


    if (TextBox1.Text == "")
    { TextBox1.Text = "0"; }
    adt.Fill(data, Int32.Parse(TextBox1.Text));

    but what i wrote for 2nd datatable(finalbal)
    plz reply me at mfaisalrah@gmail.com

    ReplyDelete
  2. hi
    Can you help me to get a job in the Gulf, Dubai, Saudi or what ever, cos am a developer with 3 years experience. (DOt Net). If its possible I would send you my resume :-)

    ReplyDelete
  3. hi asma that you are a great
    Job.thank you

    ReplyDelete