[ blackman @ 26.10.2004. 13:14 ] @
Koristi li neko ovaj data provider za MySql ?

Interesuju me primeri, nikako da ih nađem na GOOGLE.
Poseduje dobar help .chm, ali ako negde ima neki gotov primerčić radi eksperimentisanja, dobro bi došao !!!
[ Mrav @ 28.10.2004. 01:35 ] @
Pretpostavljam da se koristi kao i svaki DataProvider u .net, preko Connection, DataAdapter, Command i ostalih objekata.
[ blackman @ 28.10.2004. 07:37 ] @
Ma znam kako se koristi, nego mi se ne kodira od početka.

Tražim primer da probam sa mojom bazom, znate, zamenim ime baze, tabela itd.
[ Mrav @ 28.10.2004. 15:56 ] @
Aaaa, ti bi da ti se samo napiše! Teško da ćeš naći primer koji će odgovarati strukturi tvoje baze, ali zašto ti je problem da napišeš najosnovniji win app. sa DataGrid-om i da probaš da isčitaš neku tabelu iz baze u njega, pa za to je potrebno maksimum pola sata!
[ Mrav @ 28.10.2004. 17:26 ] @
Pazi kad me nije mrzelo!

Code:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using MySql.Data;
using MySql.Data.MySqlClient;

namespace mysql
{
    
    public class Form1 : System.Windows.Forms.Form
    {
        private System.Windows.Forms.DataGrid dataGrid1;
        private System.ComponentModel.Container components = null;
        MySqlConnection con;  // objekat veze
        DataSet podaci = new DataSet();  //data set da cuva podatke
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Button button2;
        string connection = "Data Source=localhost;Database=test;User Id=;Password="; //connection string, postavi na ono sto ti treba

        public Form1()
        {
            
            InitializeComponent();
            con = new MySqlConnection(connection); // inicijalizujemo vezu
            con.Open();
            
        }

        
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null) 
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        #region Windows Form Designer generated code
        
        private void InitializeComponent()
        {
            this.dataGrid1 = new System.Windows.Forms.DataGrid();
            this.button1 = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
            this.SuspendLayout();
            // 
            // dataGrid1
            // 
            this.dataGrid1.DataMember = "";
            this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
            this.dataGrid1.Location = new System.Drawing.Point(16, 16);
            this.dataGrid1.Name = "dataGrid1";
            this.dataGrid1.Size = new System.Drawing.Size(536, 248);
            this.dataGrid1.TabIndex = 0;
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(16, 288);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(88, 23);
            this.button1.TabIndex = 1;
            this.button1.Text = "Ucitaj tabelu";
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // button2
            // 
            this.button2.Location = new System.Drawing.Point(448, 288);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(88, 24);
            this.button2.TabIndex = 2;
            this.button2.Text = "Snimi";
            this.button2.Click += new System.EventHandler(this.button2_Click);
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(568, 341);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.button2,
                                                                          this.button1,
                                                                          this.dataGrid1});
            this.Name = "Form1";
            this.Text = "Form1";
            this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);
            ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
            this.ResumeLayout(false);

        }
        #endregion

        
        [STAThread]
        static void Main() 
        {
            Application.Run(new Form1());
        }

        private void button1_Click(object sender, System.EventArgs e)
        {
            // ovo dugme ucitava tabelu i vezuje je sa datagrid kontrolom
            MySqlDataAdapter da = new MySqlDataAdapter("select * from test",con);
            da.Fill(podaci);
            dataGrid1.DataSource = podaci.Tables[0];
        }

        private void button2_Click(object sender, System.EventArgs e)
        {
            // ovo dugme izmene vraca u bazu.
            MySqlDataAdapter da = new MySqlDataAdapter("select * from test",con);
            MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
            da.Update(podaci);
        }

        private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            con.Close();
            con.Dispose();
        }
    }
}


Mozda je ovo malo navrat nanos, ali sve se razume naravno!
[ blackman @ 01.11.2004. 09:35 ] @
Hvala za cod.
Malo sam ga preradio za VB, naravno "kad me nije mrzelo".

Ćao !!!