0

Here i am trying to insert values from form to database.when i fill in the form and hit submit, i am getting a error window saying fatal error encountered during program execution.

here is my code.

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Drawing;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;


public partial class dashboard : System.Web.UI.Page
{
    MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void submit_Click(object sender, EventArgs e)
    {
        var b = RadioButtonList1.SelectedItem.ToString();
        try
        {
            conn.Open();
            MySqlCommand cmdo = new MySqlCommand("Insert into application (applicant_fullname,applicant_age,applicant_dob,applicant_gender,applicant_residential_address) values (@Name,@password,@Email)", conn);
            cmdo.Parameters.Clear();
            cmdo.Parameters.AddWithValue("@fullname", fullname.Text);
            cmdo.Parameters.AddWithValue("@age", age.Text);
            cmdo.Parameters.AddWithValue("@dob", dateofbirth.Text);
            cmdo.Parameters.AddWithValue("@gender",b);
            cmdo.Parameters.AddWithValue("@resident", resident.Text);
            cmdo.ExecuteNonQuery();
            cmdo.Parameters.Clear();
            cmdo.Dispose();
            ShowMessage("Registered successfully......!");
        }
        catch (MySqlException ex)
        {
            ShowMessage(ex.Message);
        }

        finally
        {
            conn.Close();
        }

    }

    void ShowMessage(string msg)
    {
        ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('" + msg + "');</script>");
    }

}

asp code:

<form id="form1" runat="server">
        <table class="applytable">
        <tr><td>Full name</td><td><asp:TextBox ID="fullname" runat="server" Height="25px" Width="155px"></asp:TextBox></td></tr>
        <tr><td>Age</td><td><asp:TextBox ID="age" runat="server" Height="25px" Width="155px"></asp:TextBox></td></tr>
        <tr><td>Date Of Birth</td><td><asp:TextBox ID="dateofbirth" runat="server" Height="25px" Width="155px"></asp:TextBox></td></tr>
        <tr><td>Gender</td><td><asp:RadioButtonList ID="RadioButtonList1" runat="server">
            <asp:ListItem Value="Male"></asp:ListItem>
            <asp:ListItem Value="Female"></asp:ListItem>
        </asp:RadioButtonList></td></tr>
        <tr><td>Residential Address</td><td><asp:TextBox id="resident" TextMode="multiline" Columns="50" Rows="5" 
        runat="server" Height="58px" Width="194px" /></td></tr>
        <tr><td>Permanant Address</td><td><asp:TextBox id="permenant" TextMode="multiline" Columns="50" Rows="5" 
            runat="server" Height="68px" Width="192px" /></td></tr>
        <tr><td>Parent/Guardian name</td><td><asp:TextBox ID="parentname" runat="server" Height="25px" Width="155px"></asp:TextBox></td></tr>
        <tr><td>E-mail Address</td><td><asp:TextBox ID="emailid" runat="server" Height="25px" Width="155px"></asp:TextBox></td></tr>
        <tr><td>Phone Number</td><td><asp:TextBox ID="phoneno" runat="server" Height="25px" Width="155px"></asp:TextBox></td></tr>
        <tr><td></td><td><asp:Button ID="submitpage1" runat="server" 
                onclick="submit_Click" Text="Submit" /></td></tr>         
    </form>

How can i solve this? what am i doing wrong here?

1 Answer 1

1

I can clearly see your insert query is wrong.Your column and values does not match.

So I would recommend to run that query in mysql editor first to check insert query works.

Moreover you are adding values in parameter which are not mentioned in your queries.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.