私は友人のためにアプリを作成しており、ユーザーが値を「入力」して、それをMySQLコードに返す必要があります。このように、表示される内容が変わります。
私の問題は次のとおりです。「Form1 newForm = new Form1();」を実行すると (これは DB_Application で呼び出されます) stackoverflow エラーが発生します。
public partial class Form1
{
private DBApplication DB_App = new DBApplication();
private void InitializeComponent()
{
this.orderID.Text = "";
this.orderID.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.EnterKey);
.....
this.phoneNumber.Text = DB_App.phone_number;
.....
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void EnterKey(object o, KeyPressEventArgs e)
{
if(e.KeyChar == (char)Keys.Enter)
{
//converts the "orderID.Text" to an integer value.
if (!int.TryParse(orderID.Text, out newCurrentID))
MessageBox.Show("not a number");
e.Handled = true;
}
}
}
public class DBApplication : DBInfo
{
Form1 newForm = new Form1(); // infinite loop
public DBApplication()
{
OrderID();
}
private string OrderID ()
{
.... //reads the MySQL info, and outputs the value from the database.
}
}
ユーザーが「Enter」を押した後、値を「DB_Application」に戻す必要があるため、MySQL コマンドは値を受け取り、新しい値を出力できます。