这是我的搜索按钮:
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;
}
这是我上面的代码,当我搜索数据库时出现错误输入主号码意味着..谁能帮助我..