gpt4 book ai didi

c# - c# asp.net 程序执行过程中遇到 fatal error

转载 作者:行者123 更新时间:2023-11-29 11:54:27 25 4
gpt4 key购买 nike

这里我试图将值从表单插入到数据库。当我填写表单并点击提交时,我收到一个错误窗口,指出程序执行期间遇到 fatal error 。

这是我的代码。

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代码:

<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>

我该如何解决这个问题?我在这里做错了什么?

最佳答案

我可以清楚地看到您的插入查询是错误的。您的列和值不匹配。

所以我建议首先在 mysql 编辑器中运行该查询来检查插入查询是否有效。

此外,您在参数中添加了查询中未提及的值。

关于c# - c# asp.net 程序执行过程中遇到 fatal error ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33460631/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com