Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VS 2005 sqldatasource set parameter value to value of another parameter

Posted on 2013-12-09
6
Medium Priority
?
199 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 39707523
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
ID: 39708667
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
ID: 39708682
What method are you trying to update the parameter in?

Can you post the aspx markup code for the sqldatasource
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:lakhi
ID: 39708770
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 1200 total points
ID: 39708856
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
ID: 39709501
Thanks! It works now. That was what I needed.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

610 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