Solved

VS 2005 sqldatasource set parameter value to value of another parameter

Posted on 2013-12-09
6
189 Views
Last Modified: 2013-12-10
I'm using a VS2005 webform with a detailsview which only allows inserting a new record. The form is used to log visitor requests. Visitors may visit for only one day or multiple days.
In the instance of multiple days, the requestor enters the arrival and the end dates of the visit (visitDate and visitEndDate are the field names.)
If the visit is only one day, I would like to update the visit date to automatically be the same as the arrival date.
I'm sure there's a way to do it, I just haven't figured it out yet.
I tried this but it doesn't work. I don't get an error, it just doesn't work:
If e.Command.Parameters("@visitEndDate") Is Nothing Then
      e.Command.Parameters("@visitEndDate").Value = e.Command.Parameters("@visitDate").Value     
End If

Open in new window

Any help would be appreciated.
0
Comment
Question by:lakhi
  • 3
  • 3
6 Comments
 
LVL 29

Expert Comment

by:Paul Jackson
Comment Utility
You don't need the @, try :

If e.Command.Parameters("visitEndDate") Is Nothing Then
      e.Command.Parameters("visitEndDate").Value = e.Command.Parameters("visitDate").Value     
End If

Open in new window

0
 

Author Comment

by:lakhi
Comment Utility
I tried it without the "@" and it errors out with this message "A SqlParameter with ParameterName 'visitEndDate' is not contained by the SqlParameter Collection"
The ParameterName is "@visitEndDate" so wouldn't I need the "@?"
0
 
LVL 29

Expert Comment

by:Paul Jackson
Comment Utility
What method are you trying to update the parameter in?

Can you post the aspx markup code for the sqldatasource
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:lakhi
Comment Utility
I am using the sqldatasource_inserting method
Here is the code:
 <asp:SqlDataSource ID="vReqSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:App_DBConnectionString %>"
        InsertCommand="INSERT INTO dbo.VisitorLog(visitorName1, visitorName2, visitorName3, visitorName4, visitorName5, visitorCompany1, visitorCompany2, visitorCompany3, visitorCompany4, visitorCompany5, foreignVisitor, visitDate, purposeOfVisit, plantNo, nammoContact, nammoPhone, logDate, personalBadge, arrivalTime, requestor, visitEndDate) VALUES (@visitorName1, @visitorName2, @visitorName3, @visitorName4, @visitorName5, @visitorCompany1, @visitorCompany2, @visitorCompany3, @visitorCompany4, @visitorCompany5, @foreignVisitor, @visitDate, @purposeOfVisit, @PlantNo, @nammoContact, @nammoPhone, @logDate, @personalBadge, @arrivalTime, @requestor, @visitEndDate)"
        SelectCommand="SELECT dbo.VisitorLog.* FROM dbo.VisitorLog">
        <InsertParameters>
          <asp:Parameter Name="visitorName1" />
          <asp:Parameter Name="visitorName2" />
          <asp:Parameter Name="visitorName3" />
          <asp:Parameter Name="visitorName4" />
          <asp:Parameter Name="visitorName5" />
          <asp:Parameter Name="visitorCompany1" />
          <asp:Parameter Name="visitorCompany2" />
          <asp:Parameter Name="visitorCompany3" />
          <asp:Parameter Name="visitorCompany4" />
          <asp:Parameter Name="visitorCompany5" />
          <asp:Parameter Name="foreignVisitor" />
          <asp:Parameter Name="visitDate" />
          <asp:Parameter Name="purposeOfVisit" />
          <asp:Parameter Name="PlantNo" />
          <asp:Parameter Name="nammoContact" />
          <asp:Parameter Name="nammoPhone" />
          <asp:Parameter Name="logDate" />
          <asp:Parameter Name="personalBadge" />
          <asp:Parameter Name="arrivalTime" />
          <asp:Parameter Name="requestor" />
          <asp:Parameter Name="visitEndDate" />
        </InsertParameters>
      </asp:SqlDataSource>

Open in new window

0
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 300 total points
Comment Utility
How are you binding your form field values to the parameters, are you also doing this manually in the sqldatasource_inserting method or declaratively in the form.

Have you tried looking at the value of e.Command.Parameters("@visitEndDate") at runtime when debugging, maybe it is passing an empty string rather than being null.

So you would need to do something like :

If e.Command.Parameters("@visitEndDate") Is Nothing Or e.Command.Parameters("@visitEndDate").Value = String.Empty Then
      e.Command.Parameters("@visitEndDate").Value = e.Command.Parameters("@visitDate").Value     
End If

Open in new window

0
 

Author Comment

by:lakhi
Comment Utility
Thanks! It works now. That was what I needed.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 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

11 Experts available now in Live!

Get 1:1 Help Now