我似乎有與VS 2015的問題。在VS 2015代碼中出現錯誤
它讓我同樣的錯誤,我不知道爲什麼。我在代碼下面插入。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
textBox2.PasswordChar = '*';
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Exit_Click(object sender, EventArgs e)
{
this.Close();
}
private void LogIn_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\Gigabyte\\Desktop\\apps\\WindowsFormsApplication3\\WindowsFormsApplication3\\Database1.mdf;Integrated Security=True");
con.Open();
SqlDataAdapter sda = new SqlDataAdapter("SELECT Status FROM Login1 WHERE Username'" + textBox1.Text + "'AND Parola='" + textBox2.Text + "' ", con);
con.Close();
DataTable dt = new System.Data.DataTable();
sda.Fill(dt);
if(dt.Rows.Count==1)
{
Form2 ss = new Form2();
ss.Show();
}
}
}
}
申請表停止在sda.Fill(dt)的行;並向我顯示此錯誤:
Blockquote An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll Blockquote Additional information: Incorrect syntax near 'aa'.
任何幫助它是偉大的!先謝謝你!
編輯: 問題解決了!
歡迎堆棧溢出時會自動管理
SqlConnection
,這樣你就不需要調用Open()
或Close()
!請閱讀[問]。重要短語:「搜索和研究」和「解釋......阻止你自己解決它的任何困難」。 –請檢查您的SQL語句並瞭解如何使用參數來避免SQL注入 – sjramsay