我有这段代码从 SQL 查询中获取值并将值放在文本框中。我想把它放到另一个类,并从主类访问它。但我的问题是,该课程无法识别按钮(txtbox_ticketnum),因为它来自主课程。帮助!
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
{
txtbox_ticketnum.Text = 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");
}
}
}