namespace ClassLibrary1
{
public class open
{
SqlCommand cmd;
public SqlCommand Cmd
{
get { return cmd; }
set { cmd = value; }
}
string storedp;
public string Storedp
{
get { return storedp; }
set { storedp = value; }
}
public open(string storedp, SqlCommand cmd)
{
SqlConnection con = new SqlConnection("Data Source=.; Initial Catalog=cau; Integrated Security=true");
con.Open();
this.cmd = cmd = new SqlCommand(this.storedp = storedp, con);
this.Cmd.CommandType = CommandType.StoredProcedure;
}
}
}
それが私のウェブページ用に書いたコードです。sqlconnection
私がそれを書いたのは、どのストアド プロシージャを使用する必要があるかを伝えることができる 1 つのクラスで開きたいからです。ご覧のsqlcommand
とおりです。
しかし、問題は
protected void Page_Load(object sender, EventArgs e)
{
open op = new open("diz", cmd);
SqlDataReader rd = cmd.ExecuteReader();
while (rd.Read())
{
drop1.Items.Add(rd.GetString(0));
}
}
これは私の ASP.net ページです。クラスを実行しようとすると、「cmd のプロパティがありません」と表示され"cmd does not exist in current context"
ます。ただし、「オープン」クラスで作成しますよね?
2 番目の質問: なぜ、SqlCommand に対してだけで、文字列に対してはそうではないのですか?
注:このエラーは、名前空間、参照などの追加に関するものではありません。