anthonyricketts
Guppy
Maybe someone can help me. I am trying to insert info from textboxes into the database and do an upload to a file on a server as well. The upload works fine. However, nothing is written to the database. The database has an autonumber pk. The row is created but none of the data is stored. Can someone help? My code is listed below.
Code:
<%@ Page Language="VB" %>
<%@ Import Namespace="System.IO" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim FileUpload1 As FileUpload = CType(Me.PhotoForm.FindControl("File1"), FileUpload)
Dim FileUpload2 As FileUpload = CType(Me.PhotoForm.FindControl("File2"), FileUpload)
Dim FileUpload3 As FileUpload = CType(Me.PhotoForm.FindControl("File3"), FileUpload)
Dim FileUpload4 As FileUpload = CType(Me.PhotoForm.FindControl("File4"), FileUpload)
Dim FileUpload5 As FileUpload = CType(Me.PhotoForm.FindControl("File5"), FileUpload)
If FileUpload1.HasFile Then
Dim filepath1 As String = "./uploads/" & FileUpload1.FileName
FileUpload1.SaveAs(Server.MapPath(filepath1))
End If
If FileUpload2.HasFile Then
Dim filepath2 As String = "./uploads/" & FileUpload2.FileName
FileUpload2.SaveAs(Server.MapPath(filepath2))
End If
If FileUpload3.HasFile Then
Dim filepath3 As String = "./uploads/" & FileUpload3.FileName
FileUpload3.SaveAs(Server.MapPath(filepath3))
End If
If FileUpload4.HasFile Then
Dim filepath4 As String = "./uploads/" & FileUpload4.FileName
FileUpload4.SaveAs(Server.MapPath(filepath4))
End If
If FileUpload5.HasFile Then
Dim filepath5 As String = "./uploads/" & FileUpload5.FileName
FileUpload5.SaveAs(Server.MapPath(filepath5))
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Upload Photo</title>
</head>
<body>
<form id="form1" runat="server">
<asp:FormView ID="PhotoForm" runat="server" DataSourceID="srcPhotos" DefaultMode="Insert" HorizontalAlign="Center">
<InsertItemTemplate>
<table id="photos" runat="server" style="color: #e1ddae; font-family: Arial; background-color: #3f3f3f"><tr><td>
<!-- Set Name Properties -->
<asp:Label ID="nameLabel" runat="server" Text="Name:" />
</td><td>
<asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name")%>' />
</td></tr><tr><td>
<!-- Set Address Properties -->
<asp:Label ID="phoneLabel" runat="server" Text="Phone:" />
</td><td>
<asp:TextBox ID="phoneTextBox" runat="server" Text='<%# Bind("phone")%>' />
</td></tr><tr><td>
<!-- Set Email Properties-->
<asp:Label ID="emailLabel" runat="server" Text="E-Mail:" />
</td><td>
<asp:TextBox ID="emailTextBox" runat="server" Text='<%# Bind("email")%>' />
</td></tr><tr><td valign="top">
<!-- Set Comments Properties-->
<asp:Label ID="commentsLabel" runat="server" Text="Notes:" />
</td><td>
<asp:TextBox ID="commentsTextBox" runat="server" Width="240px" Text='<%# Bind("comments")%>' TextMode="MultiLine" /><br /><br />
</td></tr><tr><td valign="top">
<!-- Set File Properties -->
<asp:Label
ID="lblFile1" Text="Photo:" AssociatedControlID="file1" Runat="server" />
</td><td>
<asp:FileUpload ID="file1" Runat="server" FileName='<%# Bind("file1") %>' />
<br />
<asp:FileUpload ID="file2" Runat="server" FileName='<%# Bind("file2") %>' />
<br />
<asp:FileUpload ID="file3" Runat="server" FileName='<%# Bind("file3") %>' />
<br />
<asp:FileUpload ID="file4" Runat="server" FileName='<%# Bind("file4") %>' />
<br />
<asp:FileUpload ID="file5" Runat="server" FileName='<%# Bind("file5") %>' />
<br />
<asp:Button ID="btnSubmit" Text="Submit" CommandName="Insert" onClick="btnSubmit_Click" Runat="server" />
</td></tr></table>
</InsertItemTemplate>
</asp:FormView>
<asp:SqlDataSource
id="srcPhotos" Runat="server" ConnectionString="<%$ ConnectionStrings:bowlher_sunmansConnectionString %>"
SelectCommand="SELECT * FROM photos"
InsertCommand="INSERT INTO [photos] ([name], [phone], [email], [comments], [file1], [file2], [file3], [file4], [file5]) VALUES (@name, @phone, @email, @comments, @file1, @file2, @file3, @file4, @file5)">
<InsertParameters>
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="phone" Type="String" />
<asp:Parameter Name="email" Type="String" />
<asp:Parameter Name="comments" Type="String" />
<asp:Parameter Name="file1" Type="String" />
<asp:Parameter Name="file2" Type="String" />
<asp:Parameter Name="file3" Type="String" />
<asp:Parameter Name="file4" Type="String" />
<asp:Parameter Name="file5" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
</form>
</body>
</html>