私は C# と sql を初めて使用します。関数が特定のレコードのデータベース テーブルを検索する関数を C# に持っています。
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;
}
このコードは正しく実行されますが、SqlDataReader dr = newCmd.ExecuteReader(); に関しては、次のような例外がスローされます。
System.Data.dll で 'System.Data.SqlClient.SqlException' 型の未処理の例外が発生しました
追加情報: 「=」付近の構文が正しくありません。
呼び出しステートメントは
string regno = txtRegNo.Text;
txtFName.Text = update.returnstudentdata("Regno","student",regno,"Fname");
私のコードの問題は何ですか.助けてください