?
Solved

VS 2005 sqldatasource set parameter value to value of another parameter

Posted on 2013-12-09
6
Medium Priority
?
197 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

764 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