c# how to hard code data into a dataset instead of retrieving from a database

Posted on 2009-02-13
Last Modified: 2012-05-06
I need to put some code in a repeater when there is no value returned from the database query.
How can I put in the values I want for the two bits of data it woulc have got from the database had there been a record for it?

I want to put timesheetID and date into the dataset to be bound to the repeater when there is no data in the dataset

Thanks in advance
csharp code


SqlCommand commandTimesheetDayView = new SqlCommand("exec usp_GetIDForCalendarView @EmployeeID, @Date", DBConnect.conn);

        commandTimesheetDayView.Parameters.Add("EmployeeID", SqlDbType.UniqueIdentifier);

        commandTimesheetDayView.Parameters["EmployeeID"].Value = EmployeeUserID;

        commandTimesheetDayView.Parameters.Add("Date", SqlDbType.DateTime);

        commandTimesheetDayView.Parameters["Date"].Value = Date;

        commandTimesheetDayView.CommandType = CommandType.Text;

        SqlDataAdapter TimesheetDayAdapter = new SqlDataAdapter(commandTimesheetDayView);

        DataSet TimesheetDayDataSet = new DataSet();


        if (TimesheetDayDataSet == null)


            //code in here to manually put a guid of  00000-00000-0000-0000 into timesheetID and date to whatever (11/10/2008)


        RepeaterDay.DataSource = TimesheetDayDataSet;



aspx code


<EntryTimesheetControl:EntryTimesheetItem ID="EntryTimesheetItem1" TimesheetID='<%# DataBinder.Eval(Container.DataItem,"TimesheetID") %>' Date='<%# DataBinder.Eval(Container.DataItem,"Date") %>' runat="server" />

Open in new window

Question by:CharlieDev
    LVL 19

    Accepted Solution

    Create a new DataTable - no need for a DataSet
    Create the columns you need and then programatically add a new row to it with the data in you need then just bind to that.
    Make sense?

    Author Comment

    thanks, i'll have a go with that :)

    Author Closing Comment

    LVL 2

    Expert Comment


    Have you tried something like this?

                DataSet ds = new DataSet();
                ds.Tables.Add(new DataTable("somename"));
                ds.Tables[0].Columns.Add(new DataColumn("TimesheetId"));
                ds.Tables[0].Columns.Add(new DataColumn("Date"));
                ds.Tables[0].Rows.Add(new object[] {"00000-00000-0000-0000", DateTime.Now});
    LVL 19

    Expert Comment

    Ok let me know if you get stuck and I'll code it for you.  Thanks for the points.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now