الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

ريط Microsoft Visual c# 2010 بــــ My SQL

بدأه Just.walid في 20 نوفمبر 2010 · 3 رد · 927 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم و رحمة الله

كيفية ربط MYSQL 5.1 مع 2010 # Microsoft Visual C

نبدأ الشرح :

1 الأدوات المستخدمة:

Microsoft Visual C# Expresse 2010

تحميل

WampServer

تحميل

MysqlConnector ODBC

تحميل

بعد تنصيب Mysqlconnector

من Control Panel --> Administation Tolls --> Data Sources ODBC)

نطبق ما في الصورة

2lwrogj.jpg

و في C#

2b4du9.jpg

أضف هذا الكود

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 System.Data.Odbc;


namespace WindowsFormsApplication1
{

    public partial class Form1 : Form
    {
        string con;
        OdbcConnection odbCcon = new OdbcConnection();

        public Form1()
        {

            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            btnListTables.Enabled = false;

        }



        public void btnConnect_Click_1(object sender, EventArgs e)
        {
            con = "DRIVER={MySQL ODBC 5.1 Driver};SERVER=" + txtIP.Text + ";PORT=" + txtPort.Text + ";DATABASE=" + txtDatabase.Text + ";UID=" + txtUsername.Text + ";PWD=" + txtPassword.Text + ";OPTION=3";
            OdbcConnection odbCcon = new OdbcConnection(con);

           try
           {
               label6.Text = odbCcon.ConnectionString;
               txtLog.AppendText("Openning connection...\r\n");

               if (odbCcon.State == ConnectionState.Closed)
               {
                   odbCcon.Open();
               }
               if (odbCcon.State == ConnectionState.Open)
               {
                   label6.ForeColor= System.Drawing.Color.Green;
                   label6.Text = "Online";
                   btnListTables.Enabled = true;
               }

           }
           catch (System.Data.Odbc.OdbcException Ex)
           {
               txtLog.AppendText(Ex.Message + "\r\n");
               MessageBox.Show("Could not access the database.\r\nPlease make sure you completed the fields with the correct information and try    again.\r\n\r\nMore    details:\r\n" + Ex.Message, "Database connection error", MessageBoxButtons.OK, MessageBoxIcon.Error);

           }


        }

        private void btnListTables_Click(object sender, EventArgs e)
        {
            con = "DRIVER={MySQL ODBC 5.1 Driver};SERVER=" + txtIP.Text + ";PORT=" + txtPort.Text + ";DATABASE=" + txtDatabase.Text + ";UID=" + txtUsername.Text + ";PWD=" + txtPassword.Text + ";OPTION=3";
            OdbcConnection odbCcon = new OdbcConnection(con);
            odbCcon.Open();

            if (odbCcon.State == ConnectionState.Open)
            {
                OdbcCommand OdbcCom = new OdbcCommand("SHOW TABLES", odbCcon);
                OdbcDataReader OdbcDR;
                  OdbcDR = OdbcCom.ExecuteReader();
                txtLog.AppendText("DataBase Selected " + txtDatabase.Text + ":\r\n");
               while(OdbcDR.Read())
               {
                   comdatabase.Items.Add(OdbcDR[0]);

               }


            }
        }

        private void comdatabase_SelectedIndexChanged(object sender, EventArgs e)
        {

        }



        private void btndisconnect_Click(object sender, EventArgs e)
        {
            odbCcon.Close();
            if (odbCcon.State == ConnectionState.Closed)
            {
                label6.ForeColor = System.Drawing.Color.Red;
                label6.Text = "Offline";
                btnListTables.Enabled = false;
                comdatabase.Items.Clear();
                txtLog.Clear();
                txtLog.AppendText("Disconnected\r\n");
            }
        }
    }
}

الملف كامل في المرفقات

Example.rar

#2

يعطيك العافية .. والله أنا ما زبط معي

طيب شو بدنا نحط باسوورد ؟؟

ازا في مجال ترد

وشكرا سلفاً ... :) :)

#4
TareqVB كتب:

المفروض انت قمت بوضعها عندما قمت بتنصيب WampServer .

نعم و الباسورد يكون بلا قيمة

مواضيع مشابهة