C#:关键字'Table'附近的语法不正确

时间:2018-01-05 21:35:15

标签: c# sql sql-server

我正在使用SQL服务器在c#中创建一个登录窗口,跟随这个家伙教程https://www.youtube.com/watch?v=NX8-LhgFnUU

我做了一切,就像他做的那样但是当我调试应用程序并输入用户名和密码并点击登录时,我的代码出错了。它带给我代码,这是代码/截图:

代码:

private void button1_Click(object sender, EventArgs e)
{
    SqlConnection sqlcon = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=E:\eAlati - 1366x768\FastFoodDemo\DB\logindb.mdf;Integrated Security=True;Connect Timeout=30");
    string query = "Select * from Table Where username = '" + txtUsername.Text.Trim() + "'and password = '" + txtPassword.Text.Trim() + "'";

    SqlDataAdapter sda = new SqlDataAdapter(query, sqlcon);
    DataTable dtbl = new DataTable();
    sda.Fill(dtbl);

    if(dtbl.Rows.Count == 1)
    {
        ucitavanje objUcitavanje = new ucitavanje();
        this.Hide();
        objUcitavanje.Show();
    }
    else
    {
        MessageBox.Show("Vaše korisničko ime ili lozinka nisu točni! Pokušajte ponovno");
    }
}

感谢您的理解:)

1 个答案:

答案 0 :(得分:1)

对于修复我把Table放在方括号中像这样[表] 这解决了问题:D