sql - Simple C# web application with a database -


i have been @ 3 weeks , have read , watched many videos in youtube, followed t none worked me. @ point i'm pulling hairs out.

website come's out alright in web browser when textboxes filled , submit button hit database stay's empty.

so have:

=========================== original ===========================

database column fields:

firstname  middlename lastname  email phone  bttr bdtr issues 

page

first name:<asp:textbox id="first_name" runat="server" placeholder="your first name!" /> middle name:<asp:textbox id="middle_name" runat="server" placeholder="optional" /> last name:<asp:textbox id="last_name" runat="server" placeholder="last name" /> email address:<asp:textbox id="email" runat="server" placeholder="yourname@domain.com" /> phone:<asp:textbox id="phone" runat="server" placeholder="(xxx) xxx-xxxx" />   day reach you: <asp:dropdownlist id="bdtr" runat="server"> <asp:listitem>mondays</asp:listitem> <asp:listitem>tuesdays</asp:listitem> <asp:listitem>wednesdays</asp:listitem> <asp:listitem>thursdays</asp:listitem> <asp:listitem>fridays</asp:listitem> <asp:listitem>saturdays</asp:listitem> <asp:listitem>sundays</asp:listitem> </asp:dropdownlist>  time reach you: <asp:dropdownlist runat="server" name="bttr" id="bttr"> <asp:listitem text="select one" value="1">select one</asp:listitem> <asp:listitem text="6-8" value="2">6am - 8am </asp:listitem> <asp:listitem text="8-10" value="3">8am - 10am</asp:listitem> <asp:listitem text="10-12" value="4">10am - noon</asp:listitem> <asp:listitem text="12-2" value="5">noon - 2pm</asp:listitem> <asp:listitem text="2-4" value="6">2pm - 4pm</asp:listitem> <asp:listitem text="4-6" value="7">4pm - 6pm</asp:listitem> </asp:dropdownlist>  please describe health issues: <asp:textbox runat="server" name="issues" id="issues"  placeholder="examples: remember more details can provide better can you" />  <asp:button id="submit" runat="server" text="submit" cssclass="special" /><asp:label id="conflabel" runat="server" font-bold="true" forecolor="red"></asp:label></li> 

code page

using system; using system.collections.generic; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols; using system.data.sqlclient;  public partial class survey_build_platform : system.web.ui.page {     protected void page_load(object sender, eventargs e)     {       if (page.ispostback == true)         {             conflabel.text = ("*** thank - request has been submitted");         }     }     protected void submit_click(object sender, eventargs e)     {      sqlconnection cnn = new sqlconnection("data source=win-ngvi5b6ngjv/sqlexpress;initial catalog=mobilemed;integrated security=true");         {             sqlcommand xp = new sqlcommand("insert 3daytrial(refferalname, referralcodevalues(@first_name, @middle_name, @last_name, @email, @phone, @bttr, @bdtr, @issues)", cnn);             xp.parameters.addwithvalue("@first_name", first_name.text);             xp.parameters.addwithvalue("@middle_name", middle_name.text);             xp.parameters.addwithvalue("@last_name", last_name.text);             xp.parameters.addwithvalue("@email", email.text);             xp.parameters.addwithvalue("@cellphone", cell_phone.text);             xp.parameters.addwithvalue("@bttr", bttr.text);             xp.parameters.addwithvalue("@bdtr", bdtr.text);             xp.parameters.addwithvalue("@issues", goals.text);              cnn.open();             xp.executenonquery();             cnn.close();         }     } } 

=========================== modified ===========================

software:

  • windows 8 iis installed
  • sql 2012 express edition
  • visual studio community edition

database column fields:

id --- (int) firstname --- nvarchar (50, no nulls) middlename --- nvarchar (50) lastname --- nvarchar (50, no nulls) email --- nvarchar (50, no nulls) phone --- nvarchar (50, no nulls) gttr --- nvarchar (50, no nulls) gdtr --- nvarchar (50, no nulls) issues --- nvarchar (max) 

page

first name:<asp:textbox id="first_name" runat="server" placeholder="your first name!" /> middle name:<asp:textbox id="middle_name" runat="server" placeholder="optional" /> last name:<asp:textbox id="last_name" runat="server" placeholder="last name" /> email address:<asp:textbox id="email" runat="server" placeholder="yourname@domain.com" /> phone:<asp:textbox id="phone" runat="server" placeholder="(xxx) xxx-xxxx" />   day reach you: <asp:dropdownlist id="gdtr" runat="server"> <asp:listitem>mondays</asp:listitem> <asp:listitem>tuesdays</asp:listitem> <asp:listitem>wednesdays</asp:listitem> <asp:listitem>thursdays</asp:listitem> <asp:listitem>fridays</asp:listitem> <asp:listitem>saturdays</asp:listitem> <asp:listitem>sundays</asp:listitem> </asp:dropdownlist>  time reach you: <asp:dropdownlist runat="server" name="gttr" id="bttr"> <asp:listitem text="select one" value="1">select one</asp:listitem> <asp:listitem text="6-8" value="2">6am - 8am </asp:listitem> <asp:listitem text="8-10" value="3">8am - 10am</asp:listitem> <asp:listitem text="10-12" value="4">10am - noon</asp:listitem> <asp:listitem text="12-2" value="5">noon - 2pm</asp:listitem> <asp:listitem text="2-4" value="6">2pm - 4pm</asp:listitem> <asp:listitem text="4-6" value="7">4pm - 6pm</asp:listitem> </asp:dropdownlist>  please describe health issues: <asp:textbox runat="server" name="issues" id="issues"  placeholder="examples: remember more details can provide better can you" />  <asp:button id="submit" runat="server" text="submit" cssclass="special" onclick="submit_click" /><asp:label id="conflabel" runat="server" font-bold="true" forecolor="red"></asp:label> 

code page

using system; using system.collections.generic; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols; using system.data.sqlclient;  public partial class survey_build_platform : system.web.ui.page {     protected void page_load(object sender, eventargs e)     {       if (page.ispostback == true)         {             conflabel.text = ("*** thank - request has been submitted");         }     }     protected void submit_click(object sender, eventargs e)     {      sqlconnection cnn = new sqlconnection("data source=win-ngvi5b6ngjv/sqlexpress;initial catalog=smcmedc;integrated security=true");         {             sqlcommand xp = new sqlcommand("insert smcmedc (first_name, middle_name, last_name, email, phone, gttr, gdtr, goals) values (@first_name, @middle_name, @last_name, @email, @phone, @gttr, @gdtr, @issues)", cnn);             xp.parameters.addwithvalue("@firstname", first_name.text);             xp.parameters.addwithvalue("@middlename", middle_name.text);             xp.parameters.addwithvalue("@lastname", last_name.text);             xp.parameters.addwithvalue("@email", email.text);             xp.parameters.addwithvalue("@phone", cell_phone.text);             xp.parameters.addwithvalue("@gttr", gttr.text);             xp.parameters.addwithvalue("@gdtr", gdtr.text);             xp.parameters.addwithvalue("@issues", goals.text);              cnn.open();             xp.executenonquery();             int count = xp.executenonquery();              if (count != 1)                {                  conflabel.text = ("*** went wrong");                }             cnn.close();          }     } } 

insert 3daytrial(refferalname, referralcodevalues(@first_name, @middle_name, @last_name, @email, @phone, @gttr, @gdtr, @issues) 

this not valid sql me. insert statements typically have 1 of

  • values clause
  • select statement

so expect sql this:

 insert 3daytrial  values (@first_name, @middle_name, @last_name, @email, @phone, @gttr, @gdtr, @issues) 

or

 insert 3daytrial  select @first_name, @middle_name, @last_name, @email, @phone, @gttr, @gdtr, @issues 

you might need field list -- can't know because did not show important information. table names , table create statements -- understand going on need see too.


consider error checking. line

xp.executenonquery(); 

should be

int count = xp.executenonquery();  if (count != 1) {    // handle insert error } 

i suggest check return values if calling function returns value. no harm come of , writing better code.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -