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;
}
}
}
That's the code which I wrote for my web page. I wrote it because I want open sqlconnection with one class which I can tell its must use which stored proc. and which sqlcommand as you see.
But problem is
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));
}
}
This is my ASP.net page. When I try to run my class it says "there is no property for cmd" and "cmd does not exist in current context". However i create it in my "open" class Right?
Second question: why its just says for my SqlCommand but not for my string?
Note:this error is not about adding namespace ,reference or something like that.