I am new to C# and sql.I have a function in c# which searches a database table for a particular record my function is
public string returnstudentdata(string primarykey, string table, string regno, string column)
{
string temp = "";
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
SqlCommand newCmd = conn.CreateCommand();
newCmd.Connection = conn;
newCmd.CommandType = CommandType.Text;
newCmd.CommandText = "SELECT" + column + "FROM" + table + "WHERE" + primarykey + "=" + regno + "";
SqlDataReader dr = newCmd.ExecuteReader();
while (dr.Read())
{
temp = dr[column].ToString();
}
dr.Close();
conn.Close();
return temp;
}
this code executes properly but when it comes to SqlDataReader dr = newCmd.ExecuteReader(); it throws an exception stating:
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: Incorrect syntax near '='.
the calling statement is
string regno = txtRegNo.Text;
txtFName.Text = update.returnstudentdata("Regno","student",regno,"Fname");
What is the problem with my code.please help