myreader["type"] would contain the value return from the database for the user. Based on that type, you can put either a switch or if-else around showing the Main form, which can either be MainForm1 or MainForm2.
However, if you expect a single result, you could change:
while (myReader.Read())
into:
if (myReader.Read())
to make the code easier.
private void btnConnect_Click(object sender, EventArgs e)
{
try
{
string myConnection = "Server=x; Port=x; Database=x; UID=x; Pwd=x";
NpgsqlConnection myConn = new NpgsqlConnection(myConnection);
NpgsqlCommand myComm = new NpgsqlCommand("select * from Users where user='" + this.tb_user.Text + "' and password= '" + this.tb_pw.Text + "'; ", myConn);
NpgsqlDataReader myReader;
myConn.Open();
myReader = myComm.ExecuteReader();
if (myReader.Read())
{
MessageBox.Show("User and Password are correct...\nConnected!", "University");
this.Hide();
switch (myReader["type"].ToString())
{
case "teacher":
MainForm1 f1 = new MainForm1("Welcome, " + tb_user.Text.ToUpper());
f1.ShowDialog();
break;
case "student":
MainForm2 f2 = new MainForm2("Welcome, " + tb_user.Text.ToUpper());
f2.ShowDialog();
break;
default:
MessageBox.Show("Error...");
break;
}
}
else
{
MessageBox.Show("User and Password are incorrect!", "University");
}
myConn.Close();
}
catch (Exception msg)
{
MessageBox.Show(msg.Message);
throw;
}
}
Pay attention to how and when you dispose of objects like the reader and the connection.