Link to home
Create AccountLog in
Avatar of MrTV
MrTVFlag for Thailand

asked on

c# class keep it when have a call to use it

when I put line  24   string MyConString = "SERVER=localhost;" +

to  the code it error how can i put to the code be fore it inside
 private void button1_Click(object sender, EventArgs e)
        {  

it not have error i want to keep it  when i want to conect to database i just call to it
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 tabcontrolweb
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

                    string MyConString = "SERVER=localhost;" +
                "DATABASE=webboard;" +
                "UID=root;" +
                "PASSWORD='';";
            MySqlConnection connection = new MySqlConnection(MyConString);
            MySqlCommand command = connection.CreateCommand();
            MySqlDataReader Reader;
            command.CommandText = "SELECT urlwebboard  FROM `listweb` WHERE `urlwebboard` IS NOT NULL order by timestamp DESC limit 4";
            connection.Open();
            Reader = command.ExecuteReader();
            string thisrow1 = "";
            for (int i = 0; i < Reader.FieldCount; i++)
                thisrow1 += Reader.GetName(i) + ",";
            listBox1.Items.Add(thisrow1);
            System.IO.File.AppendAllText(@"C:\file.txt", thisrow1 + Environment.NewLine);


            string thisrow = "";
            string sumthisrow = "";
            while (Reader.Read())
            {
                thisrow = "";
                for (int i = 0; i < Reader.FieldCount; i++)
                    thisrow += Reader.GetValue(i).ToString()  ;
           listBox1.Items.Add(thisrow);
                System.IO.File.AppendAllText(@"C:\file.txt", thisrow + " ");
                sumthisrow = sumthisrow + thisrow + " ";
            }
            connection.Close();








        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {

        }

       
    }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of larkvale
larkvale
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
What's the error?
Avatar of MrTV

ASKER

Hi  larkvale

    it works

 what is  thecode above do

 private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {

        }



Avatar of MrTV

ASKER

Hi  larkvale
 
  last post accident
  I mean what is this line do
   
  private void Form1_Load(object sender, EventArgs e)
        {

        }

This is the Form Load event. It is called automatically when your Form first gets loaded after you start your application