mscorlib.dll中发生了未处理的“System.FormatException”类型异常 [英] An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll

查看:75
本文介绍了mscorlib.dll中发生了未处理的“System.FormatException”类型异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

mscorlib.dll中出现'System.FormatException'类型的第一次机会异常

mscorlib.dll中出现未处理的"System.FormatException"异常例外b $ b附加信息:输入字符串格式不正确。

程序'[14104] Rust Nights.vshost.exe:程序跟踪'已退出,代码为0(0x0)。 />
程序'[14104] Rust Nights.vshost.exe:Managed(v4.0.30319)'退出时代码为0(0x0)。

A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll
Additional information: Input string was not in a correct format.
The program '[14104] Rust Nights.vshost.exe: Program Trace' has exited with code 0 (0x0).
The program '[14104] Rust Nights.vshost.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).

不确定它的位置发生在。任何帮助将不胜感激。

Not sure where its occurring at. Any help would be greatly appreciated.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using MySql.Data.MySqlClient;

namespace Rust_Nights
{
    public partial class Form1 : Form
    {
        private MySqlConnection conn;
        private string server;
        private string database;
        private string uid;
        private string password;

        public Form1()
        {
            server = "sql174.main-hosting.eu";
            database = "u476341154_tehut";
            uid = "hidden";
            password = "hidden";

            string connString;
            connString = string.Format("SERVER={server};DATABASE={database};UID={uid};PASSWORD={password};");

            conn = new MySqlConnection(connString);
            InitializeComponent();
        }

        private bool OpenConnection()
        {
            try
            {
                conn.Open();
                return true;
            }
            catch (MySqlException ex)
            {
                switch (ex.Number)
                {
                    case 0:
                        MessageBox.Show("Connection to server failed!");
                        break;
                    case 1045:
                        MessageBox.Show("Server username or password is incorrect!");
                        break;
                }
                return false;
            }

        }

        public bool IsLogin(string user, string pass)
        {
            string query = string.Format("SELECT * FROM wp_users WHERE user_login='{user}' and user_pass= '{pass}';");

            try
            {
                if (OpenConnection())
                {
                    MySqlCommand cmd = new MySqlCommand(query, conn);
                    MySqlDataReader reader = cmd.ExecuteReader();

                    if (reader.Read())
                    {
                        reader.Close();
                        conn.Close();
                        return true;
                    }
                    else
                    {
                        reader.Close();
                        conn.Close();
                        return false;
                    }
                }
                else
                {
                    conn.Close();
                    return false;
                }
            }
            catch (Exception ex)
            {
                conn.Close();
                return false;
            }
        }




        private void Form1_Load(object sender, EventArgs e)
        {

        }

        string connectionString = "";
        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void Login_Button_Click(object sender, EventArgs e)
        {
            string user = Username_Textbox.Text;
            string pass = Password_Textbox.Text;

            if (IsLogin(user, pass))
            {
                MessageBox.Show("Welcome {user}!");
            }
            else
            {
                MessageBox.Show("{user} does not exist or password is incorrect!");

            }
        }
    }
}

推荐答案



由于问题与Windows窗体,我将帮助您将此主题移动到 Windows窗体常规功能论坛。你可以获得更多的专业支持


感谢您的耐心。

祝你好运,

Roy
Hi ,
Since the problem is more related to windows form, I'll help you to move this thread to the Windows Forms General Forum. You could get more professional support there.
Thank you for your patience.
Best regards,
Roy


这篇关于mscorlib.dll中发生了未处理的“System.FormatException”类型异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆