asp.netアプリケーションで使用する単純なSELECTステートメントに奇妙な問題があります。MSSQL 2008 を使用しています。
このステートメントは機能します。
SelectSQL = "SELECT user_id, user_name, user_surname, user_code FROM Users WHERE user_group = '" + drop.SelectedItem.Value + "'";
ただし、この行は「nvarchar でメソッドを呼び出すことはできません。」をスローします。
SelectSQL = "SELECT COUNT(DISTINCT Equations.eq_id) AS pocet_prikladu, Users.user_name, User.user_surname FROM Users LEFT JOIN Equations ON (Users.user_id = Equations.eq_user_id) WHERE Users.user_code = '" + drop.SelectedItem.Value + "' GROUP BY Users.user_id, Users.user_name, User.user_surname ";
ここにさらにコードがあります。最後の行で停止します
public void FillTable(Table tab, DropDownList drop) //naplneni tabulky
{
SqlConnection pripojeni = new SqlConnection(connectionString);
string SelectSQL = "";
if (action == "groups")
{
SelectSQL = "SELECT user_id, user_name, user_surname, user_code FROM Users WHERE user_group = '" + drop.SelectedItem.Value + "'";
}
else
{
SelectSQL = "SELECT COUNT(DISTINCT Equations.eq_id) AS pocet_prikladu, Users.user_name, User.user_surname FROM Users LEFT JOIN Equations ON (Users.user_id = Equations.eq_user_id) WHERE Users.user_code = '" + drop.SelectedItem.Value + "' GROUP BY Users.user_id, Users.user_name, User.user_surname ";
}
try
{
SqlCommand prikaz = new SqlCommand(SelectSQL, pripojeni);
pripojeni.Open();
SqlDataReader vysledky = prikaz.ExecuteReader();