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