-2

这是我的代码:

public userScreen(string uName)
    {
        InitializeComponent();
        userName = uName;
        string topLogNumber = "0";
        textBox2.Text = userName;
        Conversion(topLogNumber);
        textBox1.Text = topLogNumber;
        this.WindowState = FormWindowState.Maximized;

private string Conversion(string lognumber)
    {
        lognumber = gettoplognumber();
        int lognumberint = Convert.ToInt32(lognumber);
        lognumberint = lognumberint+1;
        lognumber = lognumberint.ToString();
        return lognumber;
    }

private string gettoplognumber()
    {
        string selectTopLogNumber = "SELECT MAX (LogNo) from Logs";
        string connection = "Data Source = \"EventControl.sdf\"";
        SqlCeConnection connexion = new SqlCeConnection(connection);
        SqlCeCommand topLog = new SqlCeCommand(selectTopLogNumber, connexion);
        try
        {
            connexion.Open();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
            return "error";
        }
        return topLog.ExecuteScalar() as string;

现在,这段代码所做的是查看数据库并将数字加一。当它运行时(我已经调试了整个过程),由于某种原因一切都很好,直到它到达 textBox1.Text = topLogNumber; 此时它变回“”。任何人????

4

1 回答 1

1

更改此行以获得转换的结果

topLogNumber = Conversion(topLogNumber);

或者只是将转换的结果分配给您的文本框

textBox1.Text = Conversion(topLogNumber);

里面的计算结果Conversion在return语句中传回。您需要将该计算的结果重新分配给userScreen.

于 2013-10-10T16:12:43.540 回答