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

x
?
Solved

VS2008 Formview Insert Problem

Posted on 2010-11-10
3
Medium Priority
?
471 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 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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 …
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

636 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