?
Solved

c# asp.net- how to hard code data into a dataset instead of retrieving from a database

Posted on 2009-02-13
5
Medium Priority
?
1,919 Views
Last Modified: 2012-05-06
Hi,
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();
 
        TimesheetDayAdapter.Fill(TimesheetDayDataSet);
 
        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;
 
        RepeaterDay.DataBind();
 
        DBConnect.CloseConnection();
 
 
aspx code
****************
<EntryTimesheetControl:EntryTimesheetItem ID="EntryTimesheetItem1" TimesheetID='<%# DataBinder.Eval(Container.DataItem,"TimesheetID") %>' Date='<%# DataBinder.Eval(Container.DataItem,"Date") %>' runat="server" />

Open in new window

0
Comment
Question by:CharlieDev
  • 2
  • 2
5 Comments
 
LVL 19

Accepted Solution

by:
daveamour earned 2000 total points
ID: 23632766
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?
0
 

Author Comment

by:CharlieDev
ID: 23632800
thanks, i'll have a go with that :)
0
 

Author Closing Comment

by:CharlieDev
ID: 31546568
Thanks
0
 
LVL 2

Expert Comment

by:patrickriva
ID: 23632812

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

Expert Comment

by:daveamour
ID: 23632819
Ok let me know if you get stuck and I'll code it for you.  Thanks for the points.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Screencast - Getting to Know the Pipeline
Suggested Courses

839 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