0
我正在創建一個學校項目。我的想法之一是在登錄表單後,主窗體將在用戶連接的標籤和RM(基本用戶代碼)上顯示,但我不知道如何從登錄屏幕獲取用戶名和RM並獲取RM來自數據庫。登錄後在標籤上顯示用戶名和用戶標識
登錄屏幕代碼:
public partial class Login : Form
{
public Login()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=ROCHA-PC\SQLSERVER2014;Initial Catalog=Usuarios;Integrated Security=True");
SqlDataAdapter sda = new SqlDataAdapter("Select Count(*) from users where usuario = '" + textBox1.Text + "' AND senha = '" + textBox2.Text + "'" , con);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows[0][0].ToString() == "1")
{
this.Hide();
frmTelaInicial nform = new frmTelaInicial();
nform.Show();
}
else
{
MessageBox.Show("Erro ao logar");
}
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
我怎樣才能連接的當前用戶,並顯示在標籤上?
注意:您的代碼容易受到[sql注入](https://en.wikipedia.org/wiki/ SQL_injection)攻擊。你應該看看如何使用「參數化查詢」。 – Blorgbeard