如何修复“ /”应用程序中的服务器错误。 Visual Studio mysql c#中出现错误。下面是我的代码

时间:2019-01-23 06:42:40

标签: c#

我是C#的新手,并且仍然在学习它。 我正在建立一个电话簿网站,以将我的数据存储到MySql数据库中。其中没有错误,但是它与“ /”应用程序中的服务器错误一起出现。

我已经尝试调试它,但是仍然出现相同的问题

  

“ /”应用程序中的服务器错误。

     

解析器错误

     

描述:解析服务该请求所需的资源期间发生错误。请查看以下特定的解析错误详细信息,并适当地修改您的源文件。

     

解析器错误消息:无法加载类型'_Default'。

     

源错误:

     

第1行:<%@页面标题=“主页” Language =“ C#” MasterPageFile =“〜/ Site.Master” AutoEventWireup =“ true” CodeBehind =“ Default.aspx.cs” Inherits =“ _ Default”% >

     

第2行:

     

第3行:

     

源文件:/default.aspx行:1

     

版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.7.3282.0

下面是代码

namespace Phonebooks
{
public partial class _Default : Page
{
    MySqlConnection connection = new MySqlConnection("datasource=localhost;port=3306;username=root;password=1234");
    public _Default()
    {
        InitializeComponent();
    }

    private void BTN_INSERT_Click(object sender, EventArgs e)
    {
        string insertQuery = "INSERT INTO contacts(name,position,h/pno,company's name,address,post code,state,country,tel,did,fax,email) VALUES('" + txtname.Text + "','" + txtposition.Text + "'," + txthpno.Text + "','"+txtcompanyname.Text+"','"+txtadress+"','"+txtpostcode.Text+"','"+txtstate.Text+"','"+txtcountry.Text+"','"+txttel.Text+"','"+txtdirect.Text+"','"+txtfax.Text+"',"+txtemail.Text+")";
        connection.Open();
        MySqlCommand command = new MySqlCommand(insertQuery, connection);

        try
        {
            if (command.ExecuteNonQuery() == 1)
            {
                MessageBox.Show("Data Inserted");
            }
            else
            {
                MessageBox.Show("Data Not Inserted");
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

        connection.Close();

    }
}
}

2 个答案:

答案 0 :(得分:1)

好像您在page指令中错过了名称空间。  从

更正Default.aspx文件中的第一行
  

页面标题=“主页” Language =“ C#” MasterPageFile =“〜/ Site.Master” AutoEventWireup =“ true” CodeBehind =“ Default.aspx.cs” Inherits =“ _ Default”

  

页面标题=“主页” Language =“ C#” MasterPageFile =“〜/ Site.Master” AutoEventWireup =“ true” CodeBehind =“ Default.aspx.cs” Inherits =“ Phonebooks._Default”

答案 1 :(得分:-1)

在aspx页面第一行的CodeBehind位置使用CodeFile