.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Inserting Dates

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :ASP.Net

Hi Everyone,

This is technically not a problem or issue with entity framework, but since i am using EF as my means to envoke the stored procedure I thought it would be best to post this question here.

I created a test table that has two columns:

	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[DATE_COLUMN] [datetime] NULL

I have a page that contains a textbox and an ajax control toolkit ?CalendarExtender that will allow the user to select a date from the calendar.  Actually there are 30 or so of these on the page, but if i can get the desired behavior for one I will have it for all of them.

What happens next is that on a button click event, i am firing the below stored procedure via EF:

ALTER PROCEDURE [db_owner].[sp_CSD_Insert_Dates_TEST]
@pDate datetime


	Insert into db_owner.DATETIME_TEST_TABLE (


I have imported the stored procedure into my edmx data model and created a function import from this stored procedure.  Here is the EF autogenerated function import:

Public Function CSD_INSERT_DATES_TEST(pDate As Nullable(Of Global.System.DateTime)) As Integer
        Dim pDateParameter As ObjectParameter

View Complete Post

More Related Resource Links

Inserting new row in GridView in ASP.NET 2.0

The GridView was not designed to insert new rows, but there is a way to accomplish this with very little code. This article shows how to do that. The GridView was not designed to insert new rows, but there is a way to accomplish this with very little code.

Inserting personal error message in ValidationSummary



I am creating a web form that requires a lot of validation. I use many of the validation control in asp.net already like RequiredFieldValidator and CompareValidator. 

My Problem: after my custom validation for the value entered return an error message, and I pressed enter key when the field is empty, my custom error message is overlapped by my ValidationSummary. 

Setting my custom error to visible = false on button click also does not seem to work as it requires for me to enter the value first.

This made me think, is there a way to insert my custom validation inside the ValidationSummary as an error message like for other validation control?

Thanks in advance

Inserting rows via stored procedure and under certain conditions


I'm using Dynamic Data with Entity Framework in VS2010.

Let's say my table has these fields:

PersonID (FK)
LocationID (FK)

Hypothetical scenario (it's easier for me to explain this way, so just bear with me for now)... But let's say each row in the table represents "how many items were sold by such-and-such employee at such-and-such location," where location and person are foreign keys which are referencing other tables.  Basically, there should be no more than a ONE row which has a particular combination of Person and Location.  Makes sense?

So, when inserting new rows using my Dynamic Data app, the insert form displays editable fields for Person (dropdown), Location (dropdown), and Items Sold (textbox).  How do I prevent users from inserting another row into the table containing an already-existing combination of Person and Location?   How do I displaying useful feedback to them in the event that they DO attempt to do this?

I have several thoughts about this, but since I'm new to Dynamic Data, I'm not sure which way to go.  For example:

Option 1:  Use "cascading dropdowns" approach in the insert form and only pull in the "allowed" combinations of the two dropd

LINQ to SQL - Validating if item is in Database, but if item is not items not inserting into databas



I am new to this, so bear with me.  I am writing an application in C# that uses LINQ to validate a datacontext off a textbox to see if the record exists already.  If the record does exist I inserted an if statement to advise the user that the record exists, if the record does not exist I would like to allow the record to be added to the database.  If I take out my else statement everything works fine as far as inserting goes, but I do not want to allow inserts in this scenario.  I have tried moving the if and else statement to different parts of the code but can't quite figure this one out.  Any help would be apprecaited, attached is the code.  This code is set to a button press.  As a matter of fact, if you see any other errors along the way please feel free to point them out. 



    protected void enterBTN_Click(object sender, EventArgs e)
        //make new data context

        SHCDataContext insNewAll = new SHCDataContext();
        //LINQ to check if customer exists in database
        var checkExisting = from c in insNewAll.Customers
                            where c.custLastName.Contains(custLastNameTB.Text.ToString())
                            select c.custLastName;
        //make list to store values

inserting from gridview footer


I have been following the tutorials from Scott Mitchell on this site.  I am trying to insert a new record from the gridview footer.  I have my BLL set up as a .cs class in the App Code folder.  When I fill in the fields and click add, nothing happens.  The page refreshes and the text boxes empty, but nothing is added to the database.  The edit and delete functions work fine.  Have I put something in the wrong spot?


I have the rowcommand and the datasource_inserting on the code page as below.

protected void Oems_RowCommand(object sender, GridViewCommandEventArgs e)
    // Insert data if the CommandName == "Insert" 
    // and the validation controls indicate valid data...
    if (e.CommandName == "Insert" && Page.IsValid)
        // TODO: Insert new record...

protected void OemsDataSource1_Inserting
(object sender, ObjectDataSourceMethodEventArgs e)
    // Programmatically reference Web controls in the inserting interface...
    TextBox txtOem = (TextBox)GridView1.FooterRow.FindControl("txtOem");
    TextBox txtOemStreet = (TextBox)GridView1.FooterRow.FindControl("txtOemStreet");
    TextBox txtOemCity = (TextBox)GridView1.FooterRow.FindControl("txtOemCity");

Inserting data to ExcelSheet


Hi all,

I have a web form, in that i'll enter daily expense details.

After i press save button, the data i entered are saved into an excel sheet.

I don't have idea how to save the data to excel sheet, so your help for this greatly welcome. 

Reading data from .doc or .docx and inserting into db



A vendor is providing content which needs to be inserted into the db. The content is basically questions with options and explanations. An example is below.


Need function to find difference between two dates


Hi all

I need a function written in vb to find the exact month difference between two dates.

For example

    Start Date : 01/01/2010

    End Date   : 15/02/2010

 then the difference value should be like this 1.5  i.e i need the difference in decimal value.

Cast error when inserting record with Linq (to Sql)



I'm getting  the following error message: 

Unable to cast object of type 'System.Data.Linq.DataQuery`1[Username]' to type 'Username'.

I've been searching but can't find a solution.  This particular table has 4 columns. The first column is the int indentifier.  Column 2 is "username" (varchar50) and is the primary key.  Column3 is "userID" (uniqueidentifier) and column 4 is "active" (varchar5) .

            Dim dc As New DataClassesDataContext
            Dim c3 As New Username With {.userID = userGuid, _
                                    .username = userCustomName, _
                                    .active = "False"}


        Catch ex As Exception
            Throw ex
        End Try


How to increment default dates in the subscription


I have a report that I want run on a monthly subscription, but the report has a default date parameter. Is there a way to have the default date parameter increment each month. So if I choose to receive the subscription monthly I would want that default date to increment.

Get Dates from Sunday thru Saturday


I'm using the date picker and I need to know how (or if it's even possible), to select a date, and based on the date, have the actual query use the week the date was in and return all the records from that week (Sunday through Saturday)

Like - if I pick 8/24/2010 - it returns a date range of 8/22 through 8/28
I'd also like to display the date range in the report, somehow

Any ideas on how I do this?

>>>Check duplicate while inserting record from Texbox.

Hi, On inserting record, I want to check that for example if a user enters a telephone number for any record is already in the database then it should validate that the number already exists in table and you cannot enter a duplicate value. Then if user will provide some other telephone number then he allows to insert record. For insertion of record I used ObjectdataSource. User will enter telephone number in a simple textbox. I may want to inform that I am working in asp.net2.0 and also not allowed to use any third party control or ajaxtoolkit. Any idea would be appreciated.

Inserting a row on an extract flat file

Hi, I want to add in a header row to an extracted file. The file contains 5 columns of data but I only want to add in a 5chr id (stored in a variable) in the very first line of the extracted flat file.. please can you assit and tell me the best way of doing this..

Problem inserting into XML column

I have a C# application that inserts XML into Sql Server 2005.  When the message is more than 300 lines or so, it doesn't make it there.  The data shows in the application variables (stringWriter) but doesn't get inserted and that's confirmed looking in Profiler. The stored procedure is simply:          usp_WS_OrderEntry_InsertWSOrder @doc=@p1,@WSOrderId=@p2 output       INSERT INTO WS_OrderEntry_Order (OrderXML)       VALUES(@doc)  ..... C# .....             tableAdapter.usp_WS_OrderEntry_InsertWSOrder(stringWriter.ToString(), ref wsOrderId); .... In any cases, the variable "stringWriter" contains the data (as text). In profiler for a successfull call: declare @p1 xml set @p1=convert(xml,N'<OrderHeader><CustomerNumber>1234</CustomerNumber><Pr.....</PO></ShipToName> declare @p2 int set @p2=1077 exec dbo.usp_WS_OrderEntry_InsertWSOrder @doc=@p1,@WSOrderId=@p2 output select @p2 In unsuccessfull call: It shokes on the convert part and doesn't display any data (and doesn't insert as well).  I looked in LOGs, events and didn't find anything. Any help appreciated.  Thanks.

Fetch Identity column just after inserting a row in table

Hi, Please help me with this question. I have a table and I insert a row into it. How can i select the latest inserted row? Can the 'inserted table' keyword be used outside trigger? ( I mean can we use it in above scenario?? If yes how)   Thanks in advance Tiya

QUERY filter dates by DAY

i have the following data : first column: dates and 2nd column: values i want to filter the dates per day and calculate the AVERAGE of their values per day i can filter them manually by setting day(datetimefield) = 12 and calculate the AVERGAE but i dont know how to do it for all in one query? each record resulting the average of that day   2010-07-12 00:00:00.000 900 2010-07-12 10:00:00.000 1000 2010-07-12 10:10:00.000 1200 2010-07-12 12:00:00.000 1100 2010-07-12 15:00:00.000 1300 2010-07-12 15:10:00.000 1500 2010-07-13 00:00:00.000 6500 2010-07-13 10:00:00.000 5500 2010-07-14 00:00:00.000 5500 2010-07-14 10:00:00.000 4400 2010-07-15 10:00:00.000 4500 2010-07-16 00:00:00.000 1000 2010-07-17 00:00:00.000 7000 2010-07-18 00:00:00.000 8500 2010-07-19 00:00:00.000 1500 2010-07-20 00:00:00.000 1700 2010-07-21 00:00:00.000 1900 2010-07-22 00:00:00.000 2000  

Hiding other month dates in ASP .Net Calendar Control

Often we need ASP .Net calendar control in our webpages. Most of the times we require navigation in between dates of the calendar control but there can be a requirement that when we want that users should not be able to select dates from month other than the current month.Some people might be thinking in mind that Microsoft has provided theShowNextPrevMonth property of a calendar control which can be set to false in order to disable the navigation in between months. Ok, this will disable navigation but what about the dates of adjacent months shown in current month?Following is the output of a normal Calendar control when ShowNextPrevMonth is not set to false.Note the red circles in above image. July and September will allow you to navigate through other months and red circles below will allow you to select dates of adjacent months.Ok now we set the ShowNextPrevMonth property to false and see the output. Following is the output in this case.So setting out the ShowNextPrevMonth property has disabled the July and Septemberlinks but dates of adjacent months are still there which can be selected as well. How to disable/hide these? Unfortunately there is no such default property provided using which one can disable or hide these dates but fortunately doing this using code is not a complex task. Use following code a
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend