0
這是我的搜索按鈕:未處理的SQL異常'='附近的語法不正確?
private void btnSearch_Click(object sender, EventArgs e)
{
string RegNo = txtRegNo.Text;
txtFname.Text = dba.ReturnStudentData("RegNo", "Student", RegNo, "PhoneNo");
txtLname.Text = dba.ReturnStudentData("RegNo", "Student", RegNo, "Lname");
txtPhoneNo.Text = dba.ReturnStudentData("RegNo", "Student", RegNo, "PhoneNo");
}
這是我DB_Access:
public string ReturnStudentData(string Primary_key, string Table_Name, string RegNo, string Column)
{
string temp = "";
if (conn.State.ToString() == "Closed")
{
conn.Open();
}
SqlCommand newCmd = conn.CreateCommand();
newCmd.CommandType = CommandType.Text;
newCmd.CommandText="SELECT"+Column+"FROM"+Table_Name+"WHERE"+Primary_key+"="+RegNo+"";
SqlDataReader dr = newCmd.ExecuteReader(); **// here i got error**
while(dr.Read())
{
temp = dr[Column].ToString();
}
dr.Close();
conn.Close();
return temp;
}
這是我上面的代碼,而我搜索了DB就把主號碼means..can任何人幫助我,我得到了錯誤..
打印出newCmd的內容以查看您要執行的語句。比請把這個添加到你的問題。 – smartmeta 2013-03-03 13:38:26
RegNo = null ???要麼 」」 ??? – Mortalus 2013-03-03 13:39:14
Reg No is not null .. – SDR 2013-03-03 13:41:20