I am having some trouble displaying some data I have pulled from a MySQL database. I have a text field and a search button, the user enters a name into the text field and presses the search button. The form should then close and another form opens with 3 text fields which are populated with the information from the database.
I can get the information, but I'm not sure how to pass the data over to another form; here's what I have so far.
This is my code for the search button, so after the user presses it, it stores the data it retrieves.......I think......
Firstly, what is it storing the data as? A variable? What is it? How do I call it?
private void btnSearch_Click(object sender, RoutedEventArgs e)
{
//Check the text present in the Nickname text field
if (tbNname.Text == "")
{
//If it's empty then show this message
MessageBox.Show("Please enter player nickname", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
//otherwise
else
{
try
{
//Store the contents of Nickname textbox as a variable called 'search'
string search = "'" + tbNname.Text + "'";
//Store the SQL query as a variable called 'strSQL'
string strSQL = "SELECT nickName FROM playernames WHERE nickName = "+"'search'";
//Create the connection string for the database and store it as 'conn'
MySqlConnection conn = new MySqlConnection("SERVER = localhost" + ";DATABASE=pok3r;UID=******;PASSWORD=***********;");
//Use the connection string to open a connection to the database
conn.Open();
MySqlCommand dataCommand = new MySqlCommand(strSQL, conn);
//Run the query
MySqlDataReader dataReader = dataCommand.ExecuteReader();
while (dataReader.Read())
{
searchresult result = new searchresult();
result.Show();
this.Close();
}
}
catch (Exception err)
{
MessageBox.Show(err.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
Lastly, assuming in my next form the 3 fields are tbFirst, tbSecond and tbNick. How would I display that information inside the text box?
I'm guessing it would be something along the lines of;
tbFirst.Text = thisstoredcolumn1 tbSecond.Text = thisstoredcolumn2 tbNick.Text = thisstoredcolumn3
Premier2k

New Topic/Question
Reply



MultiQuote






|