我有這個類(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();
}
哪裏'TextBox'?我看到的只是一個字符串屬性「TicketNum」!另外你的*保存點擊*真的不保存任何東西? – V4Vendetta
應該假設爲textbox.text。但我不知道如何將文本框內的值放入 – user1954418
很簡單: textbox.Text = yourvalue; –