Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
Hi. I'm having a problem regarding C#.NET. Here is the thing. The concept is like you saving document in Microsoft word and the savedialog will appear. User will key-in the name and it is then save to the respective folder.

My problem is that I am using my own windows form to prompt out instead of savedialog form and I want to show the value of input in messagebox. here is the code.

Form2
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DynamicSimulator_v2
{
    public partial class SchemaName : Form
    {
        private string data;

        public SchemaName()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            data=txtDB.Text;
            this.Hide();
        }

        public string getData()
        {
            return data;
        }

    }
}


Form 1
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using MySql.Data;
using MySql.Data.MySqlClient;

namespace DynamicSimulator_v2
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void btnNew_Click(object sender, EventArgs e)
        {
            SchemaName schemaForm = new SchemaName();
            schemaForm.Show();

            if () //I'm stuck at this part. I would like to do something like this
//  if ( schemaForm.Show() == System.Windows.Forms.Button btnOK )

            {
                MessageBox.Show(schemaForm.getData());   
            }
            /*
                       string connStr = "datasource=localhost;port=3306;username=root;password=root;";
                       MySqlConnection conn = new MySqlConnection(connStr);
                        try
                        {
                           conn.Open();
                           MySqlCommand cmdDatabase = new MySqlCommand("CREATE SCHEMA @schema; ", conn);
            
                           cmdDatabase.Parameters.AddWithValue("@schema", data.getSchema());
                           MySqlDataReader myReader;
        
                            myReader = cmdDatabase.ExecuteReader();
                            myReader.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message); 
                        }
                        conn.Close();
           
                    }*/
        }
    }
}


The main purpose I do this is to passing string value from other form to another form and used the the string value as the schema name for mysql database.
Posted
Comments
Homero Rivera 10-Oct-13 17:49pm    
you got 2 forms right? whats the name of the parent, and what's the name of the child?
arave0521 10-Oct-13 23:05pm    
parent form is Form1

1 solution

Try:
SchemaName schemaForm = new SchemaName();
if (schemaForm.ShowDialog() == DialogResult.OK)
   {
   ...
   }
and set the DialogResult property of the OK button.
 
Share this answer
 
Comments
arave0521 10-Oct-13 23:04pm    
Thank you for your help. =)
OriginalGriff 11-Oct-13 1:42am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900