Solved

VS2008 Formview Insert Problem

Posted on 2010-11-10
3
464 Views
Last Modified: 2012-08-13
Very odd issue with Formview in VS2008.

Envrionment: Sql 2005, VS2008, VB.NET
Setting: Formview bound to a sqldatasource. Has an embedded fileupload control. Clicking on insert fires the upload of the selected file to the database - works fine. However, I need to pass several other fields from the datasource to the table with the file. (definitions in code windows).  

If you look at the code_behind coding, the two fields associated with the fileupload control (attachname and attachfile) get posted to the table. The remaining fields don't get passed, regardless of whether they are set to variables, defaults or constant. Not sure what is going on.
 
Formview insert template:

                                        <InsertItemTemplate>
                                            File Name:
                                            <asp:TextBox ID="AttachNameTextBox" runat="server" Text='<%# Bind("AttachName") %>' />
                                            &nbsp; File: &nbsp;
                                            <asp:TextBox ID="WorkOrderIDTextBox" runat="server" Text='<%# Bind("WorkOrderID") %>'
                                                Visible="false" />
                                            <asp:TextBox ID="DocLinkNoTextBox" runat="server" Text='<%# Bind("DocLinkNo") %>'
                                                Visible="False" />
                                            <asp:TextBox ID="AttachDateTextBox" runat="server" Text='<%# Bind("AttachDate") %>'
                                                Visible="False" />
                                            <asp:TextBox ID="AttachByTextBox" runat="server" Text='<%# Bind("AttachBy") %>' Visible="False" />
                                            <asp:FileUpload ID="FileUpload2" runat="server" FileBytes='<%# Bind("AttachFile") %>' />
                                            <br />
                                            <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                                                Text="Upload File" />
                                            &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False"
                                                CommandName="Cancel" Text="Cancel Upload" />
                                        </InsertItemTemplate>

Open in new window


 
bound datasource:
                                       <asp:SqlDataSource ID="DocAttachDS" runat="server" ConflictDetection="CompareAllValues"
                                            ConnectionString="<%$ ConnectionStrings:ARDDBConnectionString %>" DeleteCommand="DELETE FROM [tblWorkOrderAttachments] WHERE [AttachRecID] = @original_AttachRecID AND (([WorkOrderID] = @original_WorkOrderID) OR ([WorkOrderID] IS NULL AND @original_WorkOrderID IS NULL)) AND (([DocLinkNo] = @original_DocLinkNo) OR ([DocLinkNo] IS NULL AND @original_DocLinkNo IS NULL)) AND (([Attached] = @original_Attached) OR ([Attached] IS NULL AND @original_Attached IS NULL)) AND (([AttachDate] = @original_AttachDate) OR ([AttachDate] IS NULL AND @original_AttachDate IS NULL)) AND (([AttachBy] = @original_AttachBy) OR ([AttachBy] IS NULL AND @original_AttachBy IS NULL)) AND (([AttachName] = @original_AttachName) OR ([AttachName] IS NULL AND @original_AttachName IS NULL)) AND (([AttachFile] = @original_AttachFile) OR ([AttachFile] IS NULL AND @original_AttachFile IS NULL))"
                                            InsertCommand="INSERT INTO [tblWorkOrderAttachments] ([WorkOrderID], [DocLinkNo], [Attached], [AttachDate], [AttachBy], [AttachName], [AttachFile]) VALUES (@WorkOrderID, @DocLinkNo, @Attached, @AttachDate, @AttachBy, @AttachName, @AttachFile)"
                                            OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT [WorkOrderID], [DocLinkNo], [Attached], [AttachDate], [AttachBy], [AttachName], [AttachFile], [AttachRecID] FROM [tblWorkOrderAttachments]"
                                            UpdateCommand="UPDATE [tblWorkOrderAttachments] SET [WorkOrderID] = @WorkOrderID, [DocLinkNo] = @DocLinkNo, [Attached] = @Attached, [AttachDate] = @AttachDate, [AttachBy] = @AttachBy, [AttachName] = @AttachName, [AttachFile] = @AttachFile WHERE [AttachRecID] = @original_AttachRecID AND (([WorkOrderID] = @original_WorkOrderID) OR ([WorkOrderID] IS NULL AND @original_WorkOrderID IS NULL)) AND (([DocLinkNo] = @original_DocLinkNo) OR ([DocLinkNo] IS NULL AND @original_DocLinkNo IS NULL)) AND (([Attached] = @original_Attached) OR ([Attached] IS NULL AND @original_Attached IS NULL)) AND (([AttachDate] = @original_AttachDate) OR ([AttachDate] IS NULL AND @original_AttachDate IS NULL)) AND (([AttachBy] = @original_AttachBy) OR ([AttachBy] IS NULL AND @original_AttachBy IS NULL)) AND (([AttachName] = @original_AttachName) OR ([AttachName] IS NULL AND @original_AttachName IS NULL)) AND (([AttachFile] = @original_AttachFile) OR ([AttachFile] IS NULL AND @original_AttachFile IS NULL))">
                                            <DeleteParameters>
                                                <asp:Parameter Name="original_AttachRecID" Type="Int32" />
                                                <asp:Parameter Name="original_WorkOrderID" Type="Int32" />
                                                <asp:Parameter Name="original_DocLinkNo" Type="Int32" />
                                                <asp:Parameter Name="original_Attached" Type="Boolean" />
                                                <asp:Parameter DbType="DateTime" Name="original_AttachDate" />
                                                <asp:Parameter Name="original_AttachBy" Type="String" />
                                                <asp:Parameter Name="original_AttachName" Type="String" />
                                                <asp:Parameter Name="original_AttachFile" />
                                            </DeleteParameters>
                                            <UpdateParameters>
                                                <asp:Parameter Name="WorkOrderID" Type="Int32" />
                                                <asp:Parameter Name="DocLinkNo" Type="Int32" />
                                                <asp:Parameter Name="Attached" Type="Boolean" />
                                                <asp:Parameter DbType="DateTime" Name="AttachDate" />
                                                <asp:Parameter Name="AttachBy" Type="String" />
                                                <asp:Parameter Name="AttachName" Type="String" />
                                                <asp:Parameter Name="AttachFile" Type="Object" />
                                                <asp:Parameter Name="original_AttachRecID" Type="Int32" />
                                                <asp:Parameter Name="original_WorkOrderID" Type="Int32" />
                                                <asp:Parameter Name="original_DocLinkNo" Type="Int32" />
                                                <asp:Parameter Name="original_Attached" Type="Boolean" />
                                                <asp:Parameter DbType="DateTime" Name="original_AttachDate" />
                                                <asp:Parameter Name="original_AttachBy" Type="String" />
                                                <asp:Parameter Name="original_AttachName" Type="String" />
                                                <asp:Parameter Name="original_AttachFile" />
                                            </UpdateParameters>
                                            <InsertParameters>
                                                <asp:Parameter Name="WorkOrderID" Type="Int32" />
                                                <asp:Parameter Name="DocLinkNo" Type="Int32" />
                                                <asp:Parameter Name="Attached" Type="Boolean" />
                                                <asp:Parameter Name="AttachDate" Type="DateTime" />
                                                <asp:Parameter Name="AttachBy" Type="String" />
                                                <asp:Parameter Name="AttachName" Type="String" />
                                                <asp:Parameter Name="AttachFile" />
                                            </InsertParameters>
                                        </asp:SqlDataSource>

Open in new window

code behind for ItemInserting:

   Protected Sub DocUploadView_ItemInserting(ByVal sender As Object, ByVal e As FormViewInsertEventArgs)
        Dim DocUploadDS As SqlDataSource = TryCast(WorkRequest.FindControl("DocAttachDS"), SqlDataSource)
        Dim FileUpload2 As FileUpload = TryCast(WorkRequest.FindControl("FileUpload2"), FileUpload)
        If FileUpload2.HasFile Then
            e.Values("AttachName") = FileUpload2.FileName
            e.Values("AttachFile") = FileUpload2.FileBytes
            e.Values("AttachDate") = DateTime.Now
            e.Values("Attached") = True
            e.Values("WorkOrderID") = Session("WRNum").ToString
        Else
            e.Cancel = True
        End If
    End Sub

Open in new window

0
Comment
Question by:SDBen
[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
  • 2
3 Comments
 
LVL 41

Accepted Solution

by:
guru_sami earned 500 total points
ID: 34107110
may be you might want to try OnInserting of SqlDataSource to set parameter value like
e.Command.Parameters("@AttachDate").Value = DateTime.Now
0
 

Author Closing Comment

by:SDBen
ID: 34107659
Thanks!!! That worked very nicely. Curious as to why the first version didn't work - would have though the parameters were sent either way.

Much appreciated!

Ben
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 34114215
I don't have exact idea...but in the second case you are dealing directly with the parameters before the command will be executed.
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.net Filesystem watcher not working 5 56
Copying from a network share 3 37
Call a VB.net function in Javascript 6 51
SSIS Column mapping 5 40
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

732 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