Solved

VS 2005 sqldatasource set parameter value to value of another parameter

Posted on 2013-12-09
6
192 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 300 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

947 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

19 Experts available now in Live!

Get 1:1 Help Now