user1961274
user1961274

Reputation: 11

Display data from query in textbox

This is my entire code i want to select max(pid) and want to display that into textbox

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();

    }

Upvotes: 1

Views: 1442

Answers (1)

Sam
Sam

Reputation: 10113

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

Upvotes: 2

Related Questions