Solved

Submitting form results to a database

Posted on 2006-07-07
18
535 Views
Last Modified: 2010-05-18
I have a long background in FrontPage which I've now gotten away from. I'm now using Visual Studio 2005's Visual Web Developer. One thing I can say for FP is that it was purely point and click simple to post form results to a databaes. I'm just not getting something using asp.net.

I have a survey form with 8 questions having 6-5 choice radio button based (not optional) and two text boxes (optional). I want to use the form only for entering new survey results - not to display any results at all. I'm connecting to a MSSQL 2000 database. What is the easiest method by which to accomplish this?

Here is my connection string:

<asp:sqldatasource id="SqlDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:SurveysConnectionString %>"
selectcommand="SELECT [surveyID], [q1], [q2], [q3], [q4], [datecomp], [email], [comments], [q6], [q5] FROM [ITCustSatisfaction] ORDER BY [surveyID], [datecomp]" insertcommand="INSERT INTO [Surveys].[dbo].[ITCustSatisfaction] ([surveyid],[q1],[q2],[q3],[q4],[q5],[q6],[comments],[email],[datecomp]) VALUES (surveyid, q1.SelectedValue, q2.SelectedValue, q3.SelectedValue, q4.SelectedValue, q5.SelectedValue, q6.SelectedValue, comments, email, datecomp)">
</asp:sqldatasource>

I tried setting it up using the wizard where it automatically generates the INSERT, DELETE AND UPDATE statements, but they were always greyed out and I couldn't get there from here.

[surveyid] is a hidden field on the web form and is an autogenerated number in the sql db. Q1-Q6 can be any number from 1-5 and each question is a separate radio button group list. I don't have any asp.net errors on the page right now. I'm at the point where when the user clicks "submit" I want the results posted to the db and have them directed to a surveysubmitted page (this one isn't created yet, but I can create it as an aspx page or htm, whichever it needs to be.)

Thanks for any pointers to the right direction...
0
Comment
Question by:Hers2keep
  • 9
  • 9
18 Comments
 
LVL 8

Expert Comment

by:spongie
ID: 17063689
Hi Hers2keep.

Try the following:

<asp:sqldatasource id="SqlDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:SurveysConnectionString %>"
selectcommand="SELECT [surveyID], [q1], [q2], [q3], [q4], [datecomp], [email], [comments], [q6], [q5] FROM [ITCustSatisfaction] ORDER BY [surveyID], [datecomp]"
insertcommand="INSERT INTO [Surveys].[dbo].[ITCustSatisfaction] ([surveyid],[q1],[q2],[q3],[q4],[q5],[q6],[comments],[email],[datecomp]) VALUES (@surveyid, @q1, @q2, @q3, @q4, @q5, @q6, @comments, @email, @datecomp)">
</asp:sqldatasource>

    <InsertParameters>
        <asp:ControlParameter Name="surveyid" ControlID="mySurveyIDControl" PropertyName="Value" />
        <asp:ControlParameter Name="q1" ControlID="q1" PropertyName="SelectedValue" />
        <asp:ControlParameter Name="q2" ControlID="q2" PropertyName="SelectedValue" />
        <asp:ControlParameter Name="q3" ControlID="q3" PropertyName="SelectedValue" />
        <asp:ControlParameter Name="q4" ControlID="q4" PropertyName="SelectedValue" />
        <asp:ControlParameter Name="q5" ControlID="q5" PropertyName="SelectedValue" />
        <asp:ControlParameter Name="q6" ControlID="q6" PropertyName="SelectedValue" />
        ....etc...etc....
    </InsertParameters>

...where <asp:ControlParameter Name="Equivalent to you SQL Statement Parameters (the ones with @ sign)" ControlID="Equivalent to the control name holding the value" PropertyName="The property of the control whose value you want to pass for the sql parameter e.g. Text for textboxes, Value for hidden controls " />




0
 
LVL 8

Expert Comment

by:spongie
ID: 17063694
Ooops... put the parameters between <asp:sqldatasource> </asp:sqldatasource> like:

<asp:sqldatasource id="SqlDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:SurveysConnectionString %>"
selectcommand="SELECT [surveyID], [q1], [q2], [q3], [q4], [datecomp], [email], [comments], [q6], [q5] FROM [ITCustSatisfaction] ORDER BY [surveyID], [datecomp]"
insertcommand="INSERT INTO [Surveys].[dbo].[ITCustSatisfaction] ([surveyid],[q1],[q2],[q3],[q4],[q5],[q6],[comments],[email],[datecomp]) VALUES (@surveyid, @q1, @q2, @q3, @q4, @q5, @q6, @comments, @email, @datecomp)">

    <InsertParameters>
        <asp:ControlParameter Name="surveyid" ControlID="mySurveyIDControl" PropertyName="Value" />
        <asp:ControlParameter Name="q1" ControlID="q1" PropertyName="SelectedValue" />
        <asp:ControlParameter Name="q2" ControlID="q2" PropertyName="SelectedValue" />
        <asp:ControlParameter Name="q3" ControlID="q3" PropertyName="SelectedValue" />
        <asp:ControlParameter Name="q4" ControlID="q4" PropertyName="SelectedValue" />
        <asp:ControlParameter Name="q5" ControlID="q5" PropertyName="SelectedValue" />
        <asp:ControlParameter Name="q6" ControlID="q6" PropertyName="SelectedValue" />
        ....etc...etc....
    </InsertParameters>

</asp:sqldatasource>

0
 

Author Comment

by:Hers2keep
ID: 17069339
Okay spongie - I've got that inserted now, it publishes with no errors, and the page loads with no errors; but when I click on submit the page blips like it's doing something, but no data is posted to the database.
0
 
LVL 8

Expert Comment

by:spongie
ID: 17069892
Hi Hers2keep. It would be great if you could post your code here. Maybe the whole page?
0
 

Author Comment

by:Hers2keep
ID: 17070466
Hi spongie - You got me started in the right direction and since then, I've been reading some online articles and attempting to get this page correctly formatted. I'm now using the System.Net.Mail namespace and have been going through these two links (http://www.systemnetmail.com/faq/2.1.aspx and http://www.developer.com/net/asp/article.php/3096831) trying to decipher it all. I'll post the code as it stands right now. The point at which I've stopped this evening is in the script text getting errors about variables not being declared.
========================================
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Net.Mail" %>
<script runat="server">    

    Sub btnSendMail_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim objEmail As New MailMessage()
        objEmail.To = new MailAddress("kromere@getsteno.com", "Kevin Romere");
        objEmail.Cc = new MailAddress("cadonald@getsteno.com", "Cindy Donald");
        objEmail.From = Contact_Email.Text
        objEmail.Subject = CommentOn.Text
        objEmail.Body = Contact_FullName.Text & " vbctrlf" & Contact_Title.text & " vbctrlf" & Contact_Organization.text & " vbctrlf" & Contact_StreetAddress.text & " vbctrlf" & Contact_City.text & " vbctrlf" & Contact_State.text & " vbctrlf" & Contact_Zip.text & " vbctrlf" & Contact_CountryRegion.text & " vbctrlf" & Contact_WorkPhone.text & " vbctrlf" & Contact_HomePhone.text & " vbctrlf" & Contact_FAX.Text & " vbctrlf" & Contact_Email.text & " vbctrlf" & Contact_Comments.Text & " vbctrlf" & Contact_Method.text()
        objEmail.Priority = System.Net.Mail.MailPriority.High
        objEmail.IsBodyHtml = True
// Make sure you have appropriate replying permissions from your local system
// SmtpMail.SmtpServer = "mail.getsteno.com"

        Try
            SmtpMail.Send(EMail)
            Response.Redirect(http://new.getsteno.com/emailsent.aspx)
            
        Catch exc As Exception
            Response.Write("Send failure: " + exc.ToString())
        End Try
    End Sub
</script>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta http-equiv="Content-Language" content="en-us">
<title>Contact Us</title>
</head>
<body>
<h1>Contact Us</h1>
<hr />
<p>
Please feel free to comment or request more information on any of these areas. </p>
<form id="mailform" runat="server">
<p>
<select id="CommentOn"  runat="server" name="CommentOn">
<option selected="selected">Court Reporting</option>
<option>Process Service</option>
<option>Transcription Services</option>
<option>Video Conferencing</option>
<option>Video Services</option>
<option>Website</option>
</select></p>
    <p>
Please provide the following contact information:</p>
<blockquote>
<table>
<tr>
<td align="right" style="width: 171px">
<em>Name</em></td>
<td>
<asp:textbox id="Contact_FullName" runat="server" width=477px Wrap="False"></asp:textbox>
<asp:RequiredFieldValidator ID = "req1" ControlToValidate = "Contact_FullName" Runat = "server" ErrorMessage = "Please enter your name"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td align="right" style="width: 171px">
<em>Title</em></td>
<td>
<asp:textbox id="Contact_Title"  runat="server"width=477px Wrap="False"></asp:textbox></td>
</tr>
<tr>
<td align="right" style="width: 171px">
<em>Organization</em></td>
<td>
<asp:textbox id="Contact_Organization"  runat="server"width=476px Wrap="False"></asp:textbox>
</td>
</tr>
<tr>
<td align="right" style="width: 171px">
<em>Street Address</em></td>
<td>
<asp:textbox id="Contact_StreetAddress"  runat="server"width=475px Wrap="False"></asp:textbox>
</td>
</tr>
<tr>
<td align="right" style="width: 171px">
<em>City</em></td>
<td>
<asp:textbox id="Contact_City"  runat="server"width=262px Wrap="False"></asp:textbox>
</td>
</tr>
<tr>
<td align="right" style="width: 171px">
<em>State/Province</em></td>
<td>
<asp:textbox id="Contact_State"  runat="server"width=35 Wrap="False"></asp:textbox>
</td>
</tr>
<tr>
<td align="right" style="width: 171px">
<em>Zip/Postal Code</em></td>
<td>
<asp:textbox id="Contact_Zip"  runat="server"width=121px maxlength=12 Wrap="False"></asp:textbox>
</td>
</tr>
<tr>
<td align="right" style="width: 171px">
<em>Country/Region</em></td>
<td>
<asp:textbox id="Contact_CountryRegion"  runat="server"width=54px Wrap="False"></asp:textbox>
</td>
</tr>
<tr>
<td align="right" style="width: 171px">
<em>Work Phone</em></td>
<td>
<asp:textbox id="Contact_WorkPhone"  runat="server"width=155px maxlength=25 Wrap="False"></asp:textbox>
</td>
</tr>
<tr>
<td align="right" style="width: 171px">
<em>Home Phone</em></td>
<td>
<asp:textbox id="Contact_HomePhone"  runat="server"width=154px maxlength=25 Wrap="False"></asp:textbox>
</td>
</tr>
<tr>
<td align="right" style="width: 171px">
<em>FAX</em></td>
<td>
<asp:textbox id="Contact_FAX"  runat="server" width=154px maxlength=25 Wrap="False"></asp:textbox>
</td>
</tr>
<tr>
<td align="right" style="width: 171px">
<em>E-mail</em></td>
<td>
<asp:textbox id="Contact_Email"  runat="server"width=475px Wrap="False"></asp:textbox>
<asp:RequiredFieldValidator ID = "req2" ControlToValidate = "Contact_Email" Runat = "server" ErrorMessage = "Please enter your email address"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right" style="width: 171px">
<em>Comments</em></td>
<td>
<asp:textbox id="Contact_Comments"  runat="server" width=475px></asp:textbox></td>
</tr>
    <tr>
        <td align="right" style="width: 171px">
            <em>Preferred Contact</em></td>
        <td>
<select id="Contact_Method"  runat="server" style="width: 250px">
<option selected="selected">Email</option>
<option>US Mail</option>
<option>Phone</option>
</select>
</td>
    </tr>
    <tr>
        <td align="right" colspan="2">
        </td>
    </tr>
    <tr>
        <td align="right" colspan="2" style="text-align: center">
            <asp:button id="btnSendmail" Runat="server" Text="Send Mail" OnClick="btnSendmail_Click"></asp:button>
<img src="images/clear.gif" style="width: 61px; height: 15px" />
<asp:button id="btnReset" Runat="server" Text="Reset" OnClick="btnReset_Click"></asp:button>
</td>
    </tr>
</table>
</blockquote>
<blockquote>
<p>
    &nbsp;<br />
        &nbsp;</p>
</blockquote>
<p>
    &nbsp;</p>
</form>
<hr />
<h5>
Copyright © 2006 Donald Court Reporting. All rights reserved. <br />
Revised: <!--WEBBOT BOT=TimeStamp
    S-Type="EDITED"
    S-Format="%m/%d/%y"
--></h5>
</body>
</html>
===============================================
Thanks.
0
 

Author Comment

by:Hers2keep
ID: 17072074
Serious cranial flatulence late last night. The page I posted above is another (albeit asp.net 2 also) completely different problem - not even the same website. I will post the correct code later this morning...
0
 
LVL 8

Expert Comment

by:spongie
ID: 17072085
Hi Hers2Keep. LOL. It happens...
0
 

Author Comment

by:Hers2keep
ID: 17072463
This is the real code - imposter has been captured and will be dealt with accordingly...
Present error I'm working with =
Line 36:         <asp:ControlParameter Name="comments" ControlID="comments" PropertyName="SelectedValue" Type="text"/>
================================================================
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Page language="VB" %>

<script  runat="server">
Sub submit(Source As Object, e As EventArgs)
   INSERT INTO [Surveys].[dbo].[ITCustSatisfaction] ([surveyid],[q1],[q2],[q3],[q4],[q5],[q6],[comments],      [email][datecomp]) VALUES (@surveyid, @q1, @q2, @q3, @q4, @q5, @q6, @comments, @email, @datecomp)
      If Page.IsPostBack Then Response.Redirect("surveyposted.aspx")
      End If
   End Sub
</script>

<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">
<meta http-equiv="Content-Language" content="en-us" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>AERT IT Group Customer Satisfaction Survey</title>
</head>

<body>

<form id="form1" method="post" action="surveyposted.aspx" runat="server" >

<asp:sqldatasource id="SqlDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:SurveysConnectionString %>"
selectcommand="SELECT [surveyID], [q1], [q2], [q3], [q4], [q5], [q6], [comments], [email], [datecomp] FROM [ITCustSatisfaction] ORDER BY [surveyID], [datecomp]"
insertcommand="INSERT INTO [Surveys].[dbo].[ITCustSatisfaction] ([surveyid],[q1],[q2],[q3],[q4],[q5],[q6],[comments],[email],[datecomp]) VALUES (@surveyid, @q1, @q2, @q3, @q4, @q5, @q6, @comments, @email, @datecomp)">

    <InsertParameters>
        <asp:ControlParameter Name="surveyid" ControlID="mySurveyIDControl" PropertyName="Value" />
        <asp:ControlParameter Name="q1" ControlID="q1" PropertyName="SelectedValue" Type="byte"/>
        <asp:ControlParameter Name="q2" ControlID="q2" PropertyName="SelectedValue" Type="byte"/>
        <asp:ControlParameter Name="q3" ControlID="q3" PropertyName="SelectedValue" Type="byte"/>
        <asp:ControlParameter Name="q4" ControlID="q4" PropertyName="SelectedValue" Type="byte" />
        <asp:ControlParameter Name="q5" ControlID="q5" PropertyName="SelectedValue" Type="byte" />
        <asp:ControlParameter Name="q6" ControlID="q6" PropertyName="SelectedValue" Type="byte" />
        <asp:ControlParameter Name="comments" ControlID="comments" PropertyName="SelectedValue" Type="text"/>
        <asp:ControlParameter Name="email" ControlID="email" PropertyName="SelectedValue" Type="Char"/>
    </InsertParameters>

</asp:sqldatasource>
    <h1>     AERT Information Technology Group<br />
      Customer Satisfaction Survey</h1>
      <p style="font-family: Verdana">This is an anonymous survey – giving us your email address is
      totally optional.
      However, if you would like a response, or more information, please include your
      email address and know that your problem/issue/comment will be addressed by our
      IT Director, Matthew Edwards.</p>
   <p style="font-family: Verdana">
      Using the scale of 5 being <em><strong>Very Satisfied</strong></em> and 1 being
      <em><strong>Very Dissatisfied</strong></em>, please rate the AERT IT Department (ITD) on the following:</p>

<table id="t1" border="1" width="700px" bgcolor="#FFCCCC" align="center" style="font-family: Verdana; color: #006600" cellpadding="2">
      <tr>
      <td class="style1" colspan="6" style="height: 35px">
         <strong style="font-weight: bold; font-size: x-large; color: #006600; font-family: verdana; text-align: center; font-variant: small-caps">List of Questions</strong>
     
      </td>

      </tr>
      <tr>
            <td style="height: 15px">1. The IT Department is easy to find when I need
            them.
            </td>
            <td style="height: 15px" class="style1" colspan="5"><asp:RadioButtonList id="q1"  runat="server" RepeatDirection="Horizontal">
         <asp:listitem value="5">5</asp:listitem>
         <asp:listitem value="4">4</asp:listitem>
         <asp:listitem value="3">3</asp:listitem>
         <asp:listitem value="2">2</asp:listitem>
         <asp:listitem value="1">1</asp:listitem>
      </asp:RadioButtonList></td></tr>
      <tr>
            <td>2. The It Department responds quickly once a problem has been
            reported.</td>
            <td colspan="5"><asp:RadioButtonList id="q2"  runat="server" RepeatDirection="Horizontal">
         <asp:listitem value="5">5</asp:listitem>
         <asp:listitem value="4">4</asp:listitem>
         <asp:listitem value="3">3</asp:listitem>
         <asp:listitem value="2">2</asp:listitem>
         <asp:listitem value="1">1</asp:listitem>
      </asp:RadioButtonList></td>
      </tr>
      <tr>
            <td>3.
            The IT department demonstrates knowledge about how
            to address the problem reported.
            </td>
            <td colspan="5"><asp:RadioButtonList id="q3"  runat="server" RepeatDirection="Horizontal">
                    <asp:ListItem Value="5">5</asp:ListItem>
                    <asp:ListItem Value="4">4</asp:ListItem>
                    <asp:ListItem Value="3">3</asp:ListItem>
                    <asp:ListItem Value="2">2</asp:ListItem>
                    <asp:ListItem Value="1">1</asp:ListItem>
               </asp:RadioButtonList></td>
      </tr>
      <tr>
            <td>4. The IT department quickly resolves my issues once I&#39;ve reported
            them.</td>
            <td colspan="5"><asp:RadioButtonList id="q4"  runat="server" RepeatDirection="Horizontal">
                    <asp:ListItem Value="5">5</asp:ListItem>
                    <asp:ListItem Value="4">4</asp:ListItem>
                    <asp:ListItem Value="3">3</asp:ListItem>
                    <asp:ListItem Value="2">2</asp:ListItem>
                    <asp:ListItem Value="1">1</asp:ListItem>
               </asp:RadioButtonList></td>
      </tr>
      <tr>
            <td>5. The IT department is courteous and respectful to me.</td>
            <td colspan="5"><asp:RadioButtonList id="q5"  runat="server" RepeatDirection="Horizontal">
                    <asp:ListItem Value="5">5</asp:ListItem>
                    <asp:ListItem Value="4">4</asp:ListItem>
                    <asp:ListItem Value="3">3</asp:ListItem>
                    <asp:ListItem Value="2">2</asp:ListItem>
                    <asp:ListItem Value="1">1</asp:ListItem>
               </asp:RadioButtonList></td>
      </tr>
      <tr>
            <td>6.&nbsp; The IT department keeps me informed about the progress they&#39;ve made
            on my problem.
            </td>
            <td colspan="5"><asp:RadioButtonList id="q6"  runat="server" RepeatDirection="Horizontal">
                    <asp:ListItem Value="5">5</asp:ListItem>
                    <asp:ListItem Value="4">4</asp:ListItem>
                    <asp:ListItem Value="3">3</asp:ListItem>
                    <asp:ListItem Value="2">2</asp:ListItem>
                    <asp:ListItem Value="1">1</asp:ListItem>
               </asp:RadioButtonList></td>
      </tr>
      <tr>
            <td colspan="6">7. Comments</td>
      </tr>
      <tr>
            <td colspan="6">
         <asp:textbox id="comments" runat="server" rows="4" textmode="MultiLine" width="712px" ></asp:textbox></td>
      </tr>
   <tr>
      <td colspan="6" style="height: 30px">
         8. Email Address (optional)
         <input id="email" type="text" title="Email" /></td>
   </tr>
   <tr>
      <td align="center" colspan="6">
         <input id="surveyid" type="hidden" />
         <input id="datecomp" type="hidden" value="getdate()" />
         <asp:Button id="btnSubmit" text="Submit" OnClick="submit" runat="server" />
         <input id="Reset1" type="Reset" value="Reset" />`</td>
   </tr>
</table>
</form>
</body>
</html>
0
 
LVL 8

Accepted Solution

by:
spongie earned 500 total points
ID: 17072560
Hi hers2keep.

Change your Insert parameters to this one:
    <InsertParameters>
        <asp:ControlParameter Name="surveyid" ControlID="mySurveyIDControl" PropertyName="Value" />
        <asp:ControlParameter Name="q1" ControlID="q1" PropertyName="SelectedValue" Type="byte"/>
        <asp:ControlParameter Name="q2" ControlID="q2" PropertyName="SelectedValue" Type="byte"/>
        <asp:ControlParameter Name="q3" ControlID="q3" PropertyName="SelectedValue" Type="byte"/>
        <asp:ControlParameter Name="q4" ControlID="q4" PropertyName="SelectedValue" Type="byte" />
        <asp:ControlParameter Name="q5" ControlID="q5" PropertyName="SelectedValue" Type="byte" />
        <asp:ControlParameter Name="q6" ControlID="q6" PropertyName="SelectedValue" Type="byte" />
        <asp:ControlParameter Name="comments" ControlID="comments" PropertyName="text" Type="String"/>
        <asp:ControlParameter Name="email" ControlID="email" PropertyName="text" Type="String"/>
    </InsertParameters>

you need to change control of your email input box from this:

<input id="email" type="text" title="Email" />

to this

<asp:textbox id="email" runat="server" >

:)
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:Hers2keep
ID: 17072644
Okay - done. Now this is the error I get:

<script  runat="server">
Sub submit(Source As Object, e As EventArgs)
   (INSERT INTO [Surveys].[dbo].[ITCustSatisfaction] ([surveyid],[q1],[q2],[q3],[q4],[q5],[q6],[comments],      [email][datecomp]) VALUES (@surveyid, @q1, @q2, @q3, @q4, @q5, @q6, @comments, @email, @datecomp))
      If Page.IsPostBack Then Response.Redirect("surveyposted.aspx")
   End Sub
</script>

At (Insert INTO... it says I have a syntax error.
0
 
LVL 8

Expert Comment

by:spongie
ID: 17073046
I should have read your code AND YOUR QUESTION more thoroughly...

Since you only need to insert data and not display, you can remove the "selectcommand" portion of your sqldatasource. However, it's ok if it stays there.

Change your code on Sub Submit to this one.

Sub submit(Source As Object, e As EventArgs)
       SqlDataSource1.Insert()
       If Page.IsPostBack Then Response.Redirect("surveyposted.aspx")
 End Sub
0
 

Author Comment

by:Hers2keep
ID: 17073337
Error after making above corrections:
============================================================
Exception Details: System.InvalidOperationException: Could not find control 'SurveyID' in ControlParameter 'surveyid'.
Source Error:

Line 4:  <script  runat="server">
Line 5:     Sub submit(ByVal Source As Object, ByVal e As EventArgs)
Line 6:        SqlDataSource1.Insert()
Line 7:        If Page.IsPostBack Then Response.Redirect("surveyposted.aspx")
Line 8:     End Sub
============================================================
That field should be an autogenerated number that is the primary key in the table.
0
 
LVL 8

Expert Comment

by:spongie
ID: 17078211
Hi Hers2Keep. Since this is an auto-generated ID. You don't have to include in your Insert.

insertcommand="INSERT INTO [Surveys].[dbo].[ITCustSatisfaction] ([q1],[q2],[q3],[q4],[q5],[q6],[comments],[email],[datecomp]) VALUES (@q1, @q2, @q3, @q4, @q5, @q6, @comments, @email, @datecomp)">

You may get rid of the surveyid parameters too:

<InsertParameters>
        <asp:ControlParameter Name="q1" ControlID="q1" PropertyName="SelectedValue" Type="byte"/>
        <asp:ControlParameter Name="q2" ControlID="q2" PropertyName="SelectedValue" Type="byte"/>
        <asp:ControlParameter Name="q3" ControlID="q3" PropertyName="SelectedValue" Type="byte"/>
        <asp:ControlParameter Name="q4" ControlID="q4" PropertyName="SelectedValue" Type="byte" />
        <asp:ControlParameter Name="q5" ControlID="q5" PropertyName="SelectedValue" Type="byte" />
        <asp:ControlParameter Name="q6" ControlID="q6" PropertyName="SelectedValue" Type="byte" />
        <asp:ControlParameter Name="comments" ControlID="comments" PropertyName="text" Type="String"/>
        <asp:ControlParameter Name="email" ControlID="email" PropertyName="text" Type="String"/>
    </InsertParameters>

And the hidden control:


<input id="surveyid" type="hidden" />

0
 

Author Comment

by:Hers2keep
ID: 17080695
I'm still getting the same error....


Exception Details: System.InvalidOperationException: Could not find control 'surveyid' in ControlParameter 'surveyid'.
Source Error:

Line 7:  <script  runat="server">
Line 8:     Sub submit(ByVal Source As Object, ByVal e As EventArgs)
Line 9:        SqlDataSource1.Insert()
Line 10:       If Page.IsPostBack Then Response.Redirect("surveyposted.aspx")
Line 11:    End Sub
0
 
LVL 8

Expert Comment

by:spongie
ID: 17080760
Looks like you still have this in your code:

<asp:ControlParameter Name="surveyid" ControlID="mySurveyIDControl" PropertyName="Value" />

Please delete it.

0
 

Author Comment

by:Hers2keep
ID: 17081455
Done...Now I get this error...I need to figure out how to give you more than 500 points for this!! It's days like today that I have to ask myself, "Now why did I want to move away from FrontPage????"

Must declare the variable '@datecomp'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Must declare the variable '@datecomp'.
Source Error:
Line 7:  <script  runat="server">
Line 8:     Sub submit(ByVal Source As Object, ByVal e As EventArgs)
Line 9:        SqlDataSource1.Insert()
Line 10:       If Page.IsPostBack Then Response.Redirect("surveyposted.aspx")
Line 11:    End Sub
0
 
LVL 8

Expert Comment

by:spongie
ID: 17081547
LOL...it's alright. You missed this one on the control parameters i guess:

<asp:ControlParameter Name="datecomp" ControlID="datecomp" PropertyName="value"/>

and you need to convert your hidden control to an asp server side control.  

There's an the easier and single-step way also. Never mind the control parameter above. Just revise your insert command:

insertcommand="INSERT INTO [Surveys].[dbo].[ITCustSatisfaction] ([q1],[q2],[q3],[q4],[q5],[q6],[comments],[email],[datecomp]) VALUES (@q1, @q2, @q3, @q4, @q5, @q6, @comments, @email, GETDATE())">

:)
0
 

Author Comment

by:Hers2keep
ID: 17081940
If I could have given you 5000 points for this one - I would have!

Thanks for your patience...
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now