Solved

VS 2005 sqldatasource set parameter value to value of another parameter

Posted on 2013-12-09
6
193 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
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…

773 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