我有一个表单,其中有许多文本框供用户输入数据。问题是我无法弄清楚如何从框中获取值!
用户按“保存”以保存所有值,因此我有一个“保存”此信息的过程,但正如我所说,我无法弄清楚如何提取值。我有一个搜索,发现什么都没有。继承了c#中的一些代码:
// this is the procedure i want to use the value in
public static save()
{
MessageBox.Show(trackBoxString);
}
// the event handler. trackBoxString is a public static string so that I could access it from different procedures
private void trackBox_TextChanged(object sender, EventArgs e)
{
trackBoxString = trackBox.Text;
}
这只会打开一个空白消息框
根据要求提供更多代码
public static raceBoxString =“”; public static trackBoxString =“”;
static void saveSetup()
{
try
{
string server = "localhost";
string database = "*****";
string uid = """""""";
string password = """"""";
MySqlConnection connection;
string connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password;
connection = new MySqlConnection(connectionString);
connection.Open();
connection.Close();
MessageBox.Show(trackBoxString);
}
catch (MySqlException ex)
{
MessageBox.Show(ex.ToString());
}
}
private void raceBox_TextChanged(object sender,EventArgs e) { raceBoxString = raceBox.Text; }
private void trackBox_TextChanged(object sender, EventArgs e)
{
trackBoxString = trackBox.Text;
}
答案 0 :(得分:-1)
错误是;
An object reference is required for the non-static field, method, or property