I am attempting to insert into an Access table field using a Sessionparameter. Invariably I get a Data Type Mismatch at Insert(). The Access field is defined as a long integer (foreign key to another table autonumber primary key). The Sessionparameter
is Type=Int32. The SessionParameter is pupulated on a login page with the following statement:
I've tested the insert without the Sessionparameter and everything works. In the PageLoad for this page I range test the Session field and redirect if it fails so I'm pretty sure that the Sessionfield is populated at load time. I've been struggling with
this for over a month. Greatly appreciate any help. Here's the code:
bobvinson
0 Points
1 Post
Sessionparameter Data Type Mismatch on Insert
May 27, 2009 01:40 PM|LINK
I am attempting to insert into an Access table field using a Sessionparameter. Invariably I get a Data Type Mismatch at Insert(). The Access field is defined as a long integer (foreign key to another table autonumber primary key). The Sessionparameter is Type=Int32. The SessionParameter is pupulated on a login page with the following statement:
Session("PartnerNumber") = Ctype(Partnerdv.Table.Rows(0)(0), integer)
I've tested the insert without the Sessionparameter and everything works. In the PageLoad for this page I range test the Session field and redirect if it fails so I'm pretty sure that the Sessionfield is populated at load time. I've been struggling with this for over a month. Greatly appreciate any help. Here's the code:
<form id=form1 runat="server"></form> <form id=form1 runat="server"><%@ Page Language="VB" Debug="true" %> <%@ Import Namespace="System.Web.UI.WebControls" %> <%@ Import Namespace="System.Data" %> <%@Import Namespace="System.Data.Common" %> <%@Import Namespace="System.Data.SqlClient" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <base href="file:///C:/Documents%20and%20Settings/Ginger/My%20Documents/My%20Web%20Sites/fortegp.com/add_new_prospect.aspx" fptype="TRUE" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Add New Prospect</title> <link href="style.css" rel="stylesheet" type="text/css" /> <link href="layout.css" rel="stylesheet" type="text/css" /> <style type="text/css"> .style1 { color: #CCCDCB; } .style2 { border: 2px solid #FF0000; padding-top: 1px; padding-bottom: 1px; } </style> <script type="text/vb" runat="server" > Protected sub Formview1_command(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewCommandEventArgs) if E.CommandName="Done" then response.redirect("sales_management_system_menu.htm") end if end sub Sub Page_Load(sender As Object, e As EventArgs) If Session("PartnerNumber") < 1 then response.redirect("partner_login.aspx") End if end sub </script> </head> <body style="background-image:none; margin-left: 5px; margin-right: 5px;"> <form id="form1" runat="server"> <!-- header --> <div class="main" ID=Div1> <div class="h_logo" ID=Div2> <ul> <li></li> <li></li> <li class="bg_none"></li> </ul> <a href="index.aspx"> <img src="images/logo.jpg" class="logo" alt="" style="left: -21px; top: -20px" width="280" height="83" /></a> </div> </div> <hr style="height: 5px" class="style1" noshade="noshade" /> <!-- end header --> <div> <h1>Add New Prospect</h1> <br /> <asp:FormView runat="server" id="FormView1" DataSourceID="SqlDataSource1" DataKeyNames="ContactID" OnItemCommand="FormView1_command" DefaultMode="Insert"> <EditItemTemplate> </EditItemTemplate> <InsertItemTemplate> <span class="style2">Required fields</span><br /> <br /> Honorific:<asp:DropDownList runat="server" id="DropDownList1" SelectedValue='<%# Bind("Honorific") %>'> <asp:ListItem></asp:ListItem> <asp:ListItem>Mr</asp:ListItem> <asp:ListItem>Mrs</asp:ListItem> <asp:ListItem>Ms</asp:ListItem> <asp:ListItem>Dr</asp:ListItem> <asp:ListItem>Hon</asp:ListItem> </asp:DropDownList> First Name: <asp:TextBox Text='<%# Bind("FirstName") %>' runat="server" id="FirstNameTextBox" BorderColor="Red" /> Last Name: <asp:TextBox Text='<%# Bind("LastName") %>' runat="server" id="LastNameTextBox" BorderColor="Red" /> Title: <asp:TextBox Text='<%# Bind("Title") %>' runat="server" id="TitleTextBox" /> <br /> <asp:RequiredFieldValidator runat="server" ErrorMessage="Firstname Required" id="RequiredFieldValidator1" ControlToValidate="FirstNameTextBox"> </asp:RequiredFieldValidator> <asp:RequiredFieldValidator runat="server" ErrorMessage="Lastname Required" id="RequiredFieldValidator2" ControlToValidate="LastNameTextBox"> </asp:RequiredFieldValidator> <br /> Company Name <asp:TextBox Text='<%# Bind("CompanyName") %>' runat="server" id="CompanyNameTextBox" Width="430px" BorderColor="Red" />: <br /> <asp:RequiredFieldValidator runat="server" ErrorMessage="Company Name Required" id="RequiredFieldValidator3" ControlToValidate="CompanyNameTextBox"> </asp:RequiredFieldValidator> <br /> Address: <asp:TextBox Text='<%# Bind("Address1") %>' runat="server" id="Address1TextBox" Width="360px" /> <asp:TextBox runat="server" id="Address2TextBox" Width="360px" Text='<%# Bind("Address2") %>'> </asp:TextBox> <br /> <br /> City: <asp:TextBox Text='<%# Bind("City") %>' runat="server" id="CityTextBox" /> State/Province: <asp:TextBox Text='<%# Bind("StateOrProvince") %>' runat="server" id="StateOrProvinceTextBox" Width="54px" /> Postal Code: <asp:TextBox Text='<%# Bind("PostalCode") %>' runat="server" id="PostalCodeTextBox" Width="60px" /> Country/Region: <asp:TextBox Text='<%# Bind("CountryRegion") %>' runat="server" id="CountryRegionTextBox" /> <br /> <br /> Work Phone: <asp:TextBox Text='<%# Bind("WorkPhone") %>' runat="server" id="WorkPhoneTextBox" /> Mobile Phone: <asp:TextBox Text='<%# Bind("MobilePhone") %>' runat="server" id="MobilePhoneTextBox" /> Fax Number: <asp:TextBox Text='<%# Bind("FaxNumber") %>' runat="server" id="FaxNumberTextBox" /> <br /> <br /> Email: <asp:TextBox Text='<%# Bind("EmailName") %>' runat="server" id="EmailNameTextBox" Width="256px" /> <br /> <asp:RegularExpressionValidator runat="server" ErrorMessage="Invalid email Format" id="RegularExpressionValidator1" ControlToValidate="EmailNameTextBox" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"> </asp:RegularExpressionValidator> <br /> Notes: <asp:TextBox Text='<%# Bind("Notes") %>' runat="server" id="NotesTextBox" Width="720px" TextMode="MultiLine" Height="89px" /> <br /> <br /> <asp:LinkButton runat="server" Text="Insert" CommandName="Insert" id="InsertButton" CausesValidation="True" /> <asp:LinkButton runat="server" Text="Cancel" CommandName="Cancel" id="InsertCancelButton" CausesValidation="False" /> <asp:LinkButton runat="server" id="LinkButton1" CausesValidation="False" CommandName="Done">Done</asp:LinkButton> <asp:TextBox runat="server" id="TextBox1" Text='<%# Bind("PartnerNumber") %>' Visible="False"> </asp:TextBox> <br /> <br /> </InsertItemTemplate> <ItemTemplate> ContactID: <asp:Label Text='<%# Eval("ProspectNumber") %>' runat="server" id="ContactIDLabel" /> <br /> Honorific: <asp:Label Text='<%# Bind("Honorific") %>' runat="server" id="HonorificLabel" /> <br /> FirstName: <asp:Label Text='<%# Bind("FirstName") %>' runat="server" id="FirstNameLabel" /> <br /> LastName: <asp:Label Text='<%# Bind("LastName") %>' runat="server" id="LastNameLabel" /> <br /> Address: <asp:Label Text='<%# Bind("Address1") %>' runat="server" id="AddressLabel" /> <br /> City: <asp:Label Text='<%# Bind("City") %>' runat="server" id="CityLabel" /> <br /> StateOrProvince: <asp:Label Text='<%# Bind("StateOrProvince") %>' runat="server" id="StateOrProvinceLabel" /> <br /> PostalCode: <asp:Label Text='<%# Bind("PostalCode") %>' runat="server" id="PostalCodeLabel" /> <br /> Country/Region: <asp:Label Text='<%# Bind("[CountryRegion]") %>' runat="server" id="Country_RegionLabel" /> <br /> CompanyName: <asp:Label Text='<%# Bind("CompanyName") %>' runat="server" id="CompanyNameLabel" /> <br /> Title: <asp:Label Text='<%# Bind("Title") %>' runat="server" id="TitleLabel" /> <br /> WorkPhone: <asp:Label Text='<%# Bind("WorkPhone") %>' runat="server" id="WorkPhoneLabel" /> <br /> MobilePhone: <asp:Label Text='<%# Bind("MobilePhone") %>' runat="server" id="MobilePhoneLabel" /> <br /> FaxNumber: <asp:Label Text='<%# Bind("FaxNumber") %>' runat="server" id="FaxNumberLabel" /> <br /> EmailName: <asp:Label Text='<%# Bind("EmailName") %>' runat="server" id="EmailNameLabel" /> <br /> Enteredby: <asp:Label Text='<%# Bind("PartnerNumber") %>' runat="server" id="EnteredbyLabel" /> <br /> Notes: <asp:Label Text='<%# Bind("Notes") %>' runat="server" id="NotesLabel" /> <br /> ProspectTimeStamp: <asp:Label Text='<%# Bind("ProspectTimeStamp") %>' runat="server" id="ProspectTimeStampLabel" /> <br /> </ItemTemplate> </asp:FormView> <asp:SqlDataSource runat="server" ID="SqlDataSource1" ProviderName="<%$ ConnectionStrings:ProspectsConnectionString.ProviderName %>" ConnectionString="<%$ ConnectionStrings:ProspectsConnectionString %>" SelectCommand="SELECT * FROM Prospect WHERE PartnerNumber=?;;" InsertCommand="INSERT INTO Prospect (Honorific, FirstName, LastName, Title, CompanyName, Address1, Address2, City, StateOrProvince, PostalCode, CountryRegion, WorkPhone, MobilePhone, FaxNumber, EmailName, PartnerNumber, Notes) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);"> <SelectParameters> <asp:sessionparameter SessionField="PartnerNumber" Name="?" /> </SelectParameters> <asp:insertparameters> <asp:controlparameter ControlID="FormView1$DropDownList1" Type="String" /> <asp:controlparameter ControlID="FormView1$FirstNameTextBox" Type="String" /> <asp:controlparameter ControlID="FormView1$LastNameTextBox" Type="String" /> <asp:controlparameter ControlID="FormView1$TitleTextBox" Type="String" /> <asp:controlparameter ControlID="FormView1$CompanyNameTextBox" Type="String" /> <asp:controlparameter ControlID="FormView1$Address1TextBox" Type="String" /> <asp:controlparameter ControlID="FormView1$Address2TextBox" Type="String" /> <asp:controlparameter ControlID="FormView1$CityTextBox" Type="String" /> <asp:controlparameter ControlID="FormView1$StateOrProvinceTextBox" Type="String" /> <asp:controlparameter ControlID="FormView1$PostalCodeTextBox" Type="String" /> <asp:controlparameter ControlID="FormView1$CountryRegionTextBox" Type="String" /> <asp:controlparameter ControlID="FormView1$WorkPhoneTextBox" Type="String" /> <asp:controlparameter ControlID="FormView1$MobilePhoneTextBox" Type="String" /> <asp:controlparameter ControlID="FormView1$FaxNumberTextBox" Type="String" /> <asp:controlparameter ControlID="FormView1$EmailNameTextBox" Type="String" /> <asp:sessionparameter SessionField="PartnerNumber" Type="Int32" /> <asp:controlparameter ControlID="FormView1$NotesTextBox" Type="String" /> </asp:insertparameters> </asp:SqlDataSource> </div> <div class="short_footer"> <div class="main"> <div class="footer">Forte Group © 2008 | <a href="Forte_privacypolicy.aspx">Privacy Policy</a></div> </div> </div> </form> </body> </html>Any insight greatly appreciated.
</form>SQLdatasource DataType Mismatch Access database Sessionparameter