显示文本框中查询的数据

时间:2013-01-09 21:59:51

标签: c#

这是我的整个代码,我想选择max(pid)并希望将其显示到文本框

public PatientRegistration()
    {
        InitializeComponent();
        string connectionstring = "DATABASE=hmanagmentsystem;UID=root;PASSWORD=;SERVER=localhost";
        con = new MySqlConnection(connectionstring);
        con.Open();
    }

  private void PatientRegistration_Load(object sender, EventArgs e)
    {

        MySqlCommand command = new MySqlCommand("select max(pid) from patientreg",con);
        txtpatientid.Text = command.ToString();
        con.Close();

    }

1 个答案:

答案 0 :(得分:2)

txtpatientid.Text = command.ExecuteScalar().ToString();