我有这个类(Class1
)从查询中检索值。现在我想让它面向对象,这就是我这样写的原因。现在的问题是,TextBox
( TicketNum
) 不会返回值并在表单中显示它。我不知道为什么。帮助。
public partial class Main : System.Web.UI.Page
{
private String _TicketNum;
public String TicketNum
{
get { return _TicketNum; }
set { _TicketNum = value; }
}
}
public class Class1
{
Main main = new Main();
public void SelectTop1()
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
{
using (SqlCommand com_retrieve = new SqlCommand("usp_SelectTop1Ticket", con))
{
com_retrieve.CommandType = CommandType.StoredProcedure;
con.Open();
try
{
main.TicketNum = com_retrieve.ExecuteScalar().ToString();
MessageBox.Show("Ticket Has been saved. Your Ticket Number: " + com_retrieve.ExecuteScalar().ToString(), "Ticket Filed");
}
catch (SqlException)
{
MessageBox.Show("The database has encountered an error");
}
catch (Exception)
{
MessageBox.Show("The server has encountered an error");
}
}
}
}
}
protected void btn_Save_Click(object sender, EventArgs e)
{
Class1 selectTop1 = new Class1();
selectTop1.SelectTop1();
}