Connection property has not been initialized.

Connection property has not been initialized.

Postby Zer0 » Mon 24 Jul 2006 08:31

When I run the text below I get this error ..

Code: Select all
if (box2.Text == box3.Text & mySqlConnection1.State == ConnectionState.Open)
            {
                try
                {
                    mySqlScript1.Execute();
                }
                catch (System.Exception)
                {
                    textBox4.AppendText("Username Taken,\r\nPlease try a different one.");
                    //mySqlConnection1.Close();
                }
                this.mySqlScript2.Name = "mySqlScript2";
                this.mySqlScript2.ScriptText = "INSERT INTO 'accounts' VALUES ('username.Text', 'box2.Text', '1');";
                mySqlScript2.Execute();
                textBox4.AppendText(" You are now registered ");

            }


ANy help with this is greatly appreciated
Zer0
 

Postby Alexey » Mon 24 Jul 2006 08:47

Connection property of mySqlScript1 component has not been initialized in your code. Do this first before running mySqlScript1.Execute()
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Postby Zer0 » Mon 24 Jul 2006 08:58

Then I get issues with the ; not being there

Error 1 ; expected C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\Rose Launcher\Rose Launcher\Form2.cs 79 43 Rose Launcher


Code: Select all
if (box2.Text == box3.Text & mySqlConnection1.State == ConnectionState.Open)
            {
                try
                {
                    //mySqlScript1.Connection = mySqlScript1.Connection;
                    mySqlScript1.Execute()
                    mySqlScript1.Execute();
                }
                catch (System.Exception)
                {
                    textBox4.AppendText("Username Taken,\r\nPlease try a different one.");
                    //mySqlConnection1.Close();
                }
                this.mySqlScript2.Name = "mySqlScript2";
                this.mySqlScript2.ScriptText = "INSERT INTO 'accounts' VALUES ('username.Text', 'box2.Text', '1');";
                //mySqlScript2.Connection = mySqlScript2.Connection;
                mySqlScript2.Execute()
                mySqlScript2.Execute();
                textBox4.AppendText(" You are now registered ");


I added in the mySqlScript2.Execute() and mySqlScript1.Execute()
Zer0
 

Postby Zero » Mon 24 Jul 2006 09:01

n/m .. how to I set the connection ?

Code: Select all
mySqlScript2.Connection = mySqlScript2.Connection;
?
Zero
 

Postby Alexey » Mon 24 Jul 2006 10:53

Use the following code:
Code: Select all
      mySqlConnection1.ConnectionString = "User Id=root;Password=root;Host=localhost;Database=test;";
      mySqlScript1.Connection = mySqlConnection1;
      mySqlConnection1.Open();
      mySqlScript1.Execute();
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43


Return to dotConnect for MySQL