تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
ماهي طريقة الاتصال بقاعدة البيانات الموجودة في موقع الانترنت
#1
السلام عليكم
اخواني قبل كل شي بحثت في المنتدى عن هذه الطريقه ولم اجدها
وبعض المواضيع متشابهه وبعضها تتعلق بقاعدة بيانات mysql و mysql server

انا رفعت قاعدة بيانات على موقع مجاني من نوع mysql

واستخدمت عدة اكواد على الفيجوال بيسك دوت نت بدون فائدة
وهذا هو الكود الذي استخدمه في الفيجوال بيسك

PHP كود :
Imports System.Data
Imports MySql
.Data.MySqlClient
Public Class Manage_user
    Dim con 
As New MySqlConnection
    Dim result 
As Integer
    
'MySqlCommand It represents a SQL statement to execute against a MySQL Database
    Dim cmd As New MySqlCommand
    '
Represents a set of data commands and a database connection that 
    
'are used to fill a dataset and update a MySQL database. This class cannot be inherited.
    Dim da As New MySqlDataAdapter

    Private Sub btncreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncreate.Click
        '
this line of is simply we copy this one from our form 
        con
.ConnectionString = ("server=localhost;user id=root;password=;database=androidhive")

        Try
            
'we open Connection
            con.Open()

            With cmd
                .Connection = con
                .CommandText = "INSERT INTO `androidhive`.`products` (`pid`, `name`, `price`, `description`) " & _
                                "VALUES (NULL, '" & txtfullname.Text & "', '" & txtusername.Text & "', '" & txtpassword.Text & "');"
                '
in this line it Executes a transact-SQL statements against the connection and returns the number of rows affected 
                result 
cmd.ExecuteNonQuery
                
'if the result is equal to zero it means that no rows is inserted or somethings wrong during the execution
                If result = 0 Then
                    MsgBox("Data has been Inserted!")
                Else
                    MsgBox("Successfully saved!")

                End If
            End With
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        con.Close()
    End Sub

    Private Sub btnload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnload.Click
        '
again we do this because we do not yet declare this as global, but we do it for now beacause in later tutorial
        
'we will do the moduling and more on refactoring of codes
        con.ConnectionString = ("server=localhost;user id=root;password=;database=androidhive")
        Try
            con.Open()
            With cmd
                .Connection = con
                '
in this query it does simply selecting or getting all the user found in the database.
                .
CommandText "Select * from products"
            
End With

        
Catch ex As Exception
            MsgBox
(ex.Message)


        
End Try
        
con.Close()
        
da.Dispose()
        
filltable(dtguser)

    
End Sub
    
' this our sub procedure that well always used 
    '
this beacause it always catch all the result query 
    
'and it will display to any kind of visual basic containers like datagridview,listbox,listview, etc...
    Public Sub filltable(ByVal dtgrd As Object)
        '
declare a variable as new datatable
        Dim publictable 
As New DataTable
        
Try
            
'Gets or sets an SQL statement or stored procedure used to select records in the database.
            da.SelectCommand = cmd
            da.Fill(publictable)
            dtgrd.DataSource = publictable
            dtgrd.Columns(0).Visible = False

            da.Dispose()

        Catch ex As Exception
            MsgBox(ex.Message)

        End Try

    End Sub

    Private Sub Manage_user_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class 

لم اجد الطريقة في بعض مواقع الانترنت واتمنى ان اجدها هنا

علما بأن قاعدة البيانات مستخدمه في موقع مجاني اسمه
hostinger.ae

شكرا لكم
الرد }}}
تم الشكر بواسطة:
#2
انتظرني قريبا سأعمل فيديو عن هذا الموضوع
الرد }}}
تم الشكر بواسطة: Amir_Alzubidy
#3
بانتظارك اخي الكريم
وشكرا على التواصل
الرد }}}
تم الشكر بواسطة:
#4
هل الموق يدعم اتصال البيانات عن بُعد ؟
تأكد من ذلك
الرد }}}
تم الشكر بواسطة:
#5
.....

بعد الاطلاع على هذا الموضوع وموضوع آخر لك (ماهي المشكلة في مشروعي . ربط قاعدة بيانات mysql)




منقول مع تعديل بسيط ليناسب طلبك


كود :
Imports MySql.Data.MySqlClient

Public Class Form1

    Dim con As New MySqlConnection(" Server = db4free.net;  Port = 3306;  Database = vbnet; " _
                                 & " User id = vbnet;  Password = 10241024;                 ")


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' إعدادات خصائص بعض الأدوات يمكن الإستغناء عن هذه الأسطر بتعيينها من خلال نافذة الخصائص
        Me.btnInsert.Text = "إضافة"
        Me.btnUpdate.Text = "تحديث"
        Me.btnDelete.Text = "حذف"
        Me.btnInsert.Enabled = False
        Me.btnUpdate.Enabled = False
        Me.btnDelete.Enabled = False
        Me.txtPID.Enabled = False
        '---
        Me.DataGridView1.AllowUserToAddRows = False
        Me.DataGridView1.AllowUserToDeleteRows = False
        Me.DataGridView1.ReadOnly = True
        Me.DataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect
        Me.DataGridView1.MultiSelect = False
        '------------------------
        ' إستعجال ظهور النافذة
        Me.Show()
        Application.DoEvents()
        '------------------------
        ' إستدعاء تعبئة البيانات
        If DataGridView1Fill() Then
            Me.btnInsert.Enabled = True
        End If
    End Sub



    ' إضافة
    Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsert.Click

        If Me.btnInsert.Text = "جديد" Then
            ' إستدعاء الوضع الإفتراضي للأدوات
            Reset()
            Exit Sub
        End If

        If (Me.txtName.Text.Trim = String.Empty) Or (Not IsNumeric(Me.txtPrice.Text)) Then
            MsgBox("تأكد من البيانات")
            Exit Sub
        End If

        Try
            Dim sql As String = " INSERT INTO `products` ( `name`, `price`, `description`, `expiredate` ) " & _
                                "                 Values ( @name,  @price,  @description,  @expiredate  ) "
            Using cm As New MySqlCommand(sql, con)
                cm.Parameters.AddWithValue("@name", Me.txtName.Text.Trim)
                cm.Parameters.AddWithValue("@price", Me.txtPrice.Text.Trim)
                cm.Parameters.AddWithValue("@description", Me.txtDescription.Text.Trim)
                'cm.Parameters.AddWithValue("@expiredate", Me.DateTimePicker1.Value.Date) '' إذا كان الحقل تاريخ فقط بدون وقت
                cm.Parameters.AddWithValue("@expiredate", Me.DateTimePicker1.Value) '' هنا التاريخ مع الوقت

                con.Open()
                cm.ExecuteNonQuery()
                con.Close()

            End Using

            ' إستدعاء الوضع الإفتراضي للأدوات
            Reset()

            MsgBox("تمت الإضافة بنجاح")

            DataGridView1Fill()

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try


    End Sub



    ' تحديث
    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click

        If MsgBox("هل أنت متأكد من البيانات", MsgBoxStyle.MsgBoxRight + MsgBoxStyle.MsgBoxRtlReading + MsgBoxStyle.YesNo + MsgBoxStyle.Question) <> MsgBoxResult.Yes Then
            Exit Sub
        End If

        If (Val(Me.txtPrice.Text) < 0) _
              Or (Me.txtName.Text.Trim = String.Empty) _
              Or (Not IsNumeric(Me.txtPrice.Text)) _
              Then
            MsgBox("تأكد من البيانات")
            Exit Sub
        End If

        Try
            Dim sql As String = " UPDATE `products`                 " & _
                                " SET `name`  = @name               " & _
                                "   , `price` = @price              " & _
                                "   , `description` = @description  " & _
                                "   , `expiredate`  = @expiredate   " & _
                                " WHERE `pid` = @pid                "

            Using cm As New MySqlCommand(sql, con)
                cm.Parameters.AddWithValue("@name", Me.txtName.Text.Trim)
                cm.Parameters.AddWithValue("@price", Me.txtPrice.Text.Trim)
                cm.Parameters.AddWithValue("@description", Me.txtDescription.Text.Trim)
                cm.Parameters.AddWithValue("@expiredate", Me.DateTimePicker1.Value)
                cm.Parameters.AddWithValue("@pid", Val(Me.txtPID.Text))

                con.Open()
                cm.ExecuteNonQuery()
                con.Close()

            End Using

            ' إستدعاء الوضع الإفتراضي للأدوات
            Reset()

            MsgBox("تم التحديث بنجاح")

            DataGridView1Fill()

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub



    ' حذف
    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click

        If MsgBox("هل أنت متأكد من حذف البيانات", MsgBoxStyle.MsgBoxRight + MsgBoxStyle.MsgBoxRtlReading + MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton2 + MsgBoxStyle.Exclamation) <> MsgBoxResult.Yes Then
            If MsgBox("هل أنت فعلاً متأكد من حذف البيانات", MsgBoxStyle.MsgBoxRight + MsgBoxStyle.MsgBoxRtlReading + MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton2 + MsgBoxStyle.Exclamation) <> MsgBoxResult.Yes Then
                Exit Sub
            End If
        End If

        Try
            Dim sql As String = " Delete From `products`    " & _
                                " WHERE `pid` = @pid        "
            Using cm As New MySqlCommand(sql, con)
                cm.Parameters.AddWithValue("@pid", Val(Me.txtPID.Text))

                con.Open()
                cm.ExecuteNonQuery()
                con.Close()

            End Using

            ' إستدعاء الوضع الإفتراضي للأدوات
            Reset()

            MsgBox("تم الحذف بنجاح")

            DataGridView1Fill()

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub



    ' تعبئة أداة الجدول بالبيانات
    Public Function DataGridView1Fill() As Boolean
        Try
            Using da As New MySqlDataAdapter("Select * from `products`", con)
                Using dt As New DataTable
                    da.Fill(dt)
                    DataGridView1.DataSource = dt
                    If DataGridView1.Rows.Count > 0 Then
                        DataGridView1.Columns(0).HeaderText = "ID"
                        DataGridView1.Columns(0).Width = 50
                        DataGridView1.Columns(1).HeaderText = "الإسم"
                        DataGridView1.Columns(1).Width = 150
                        DataGridView1.Columns(2).HeaderText = "السعر"
                        DataGridView1.Columns(2).Width = 70
                        DataGridView1.Columns(3).HeaderText = "الوصف"
                        DataGridView1.Columns(3).Width = 200
                        DataGridView1.Columns(4).HeaderText = "تاريخ الصلاحية"
                        DataGridView1.Columns(4).Width = 110
                    End If
                End Using
            End Using

            Return True

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Function



    ' الاختيار بالنقر المزدوج

    ' عند النقر المزدوج رأس السطر
    Private Sub DataGridView1_RowHeaderMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.RowHeaderMouseDoubleClick
        RowSelect(e.RowIndex)
    End Sub
    ' عند النقر المزدوج على أي خلية في سطر
    Private Sub DataGridView1_CellContentDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentDoubleClick
        RowSelect(e.RowIndex)
    End Sub
    ' قراءة بيانات السطر الذي تم اختياره بالنقر المزدوج
    Private Sub RowSelect(ByVal rowIndex As Integer)
        Me.txtPID.Text = DataGridView1.Item(0, rowIndex).Value
        Me.txtName.Text = DataGridView1.Item(1, rowIndex).Value
        Me.txtPrice.Text = DataGridView1.Item(2, rowIndex).Value
        Me.txtDescription.Text = DataGridView1.Item(3, rowIndex).Value
        Me.DateTimePicker1.Text = DataGridView1.Item(4, rowIndex).Value
        Me.btnInsert.Text = "جديد"
        Me.btnUpdate.Enabled = True
        Me.btnDelete.Enabled = True
        Me.DataGridView1.Enabled = False
    End Sub



    ' إعادة الأدوات للوضع الإفتراضي
    Private Sub Reset()

        Me.txtPID.Text = ""
        Me.txtName.Text = ""
        Me.txtPrice.Text = ""
        Me.txtDescription.Text = ""
        Me.DateTimePicker1.Text = Now

        Me.btnInsert.Text = "إضافة"
        Me.btnUpdate.Enabled = False
        Me.btnDelete.Enabled = False

        Me.DataGridView1.Enabled = True

    End Sub


End Class

.....


الملفات المرفقة
.rar   WindowsApplication1.rar (الحجم : 160.5 ك ب / التحميلات : 110)
الرد }}}
تم الشكر بواسطة: Amir_Alzubidy
#6
اشكرك اخي الكريم vbnet
سأقوم بتجربته حالا
واذا كان لديك المشروع يمكنك اضافته هنا لربما يستفيد منه غيري

شكرا مرة ثانية
الرد }}}
تم الشكر بواسطة:
#7
اخي الكريم vbnet
للاسف الكود لا يعمل
واتمنى ان ارسل لك تفاصيل موقعي حتى تتمكن من رؤية المشكلة

شكرا لك
الرد }}}
تم الشكر بواسطة:


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  ماهي الجداول التي احتاجها لنظام رواتب متكامل Adel27213 0 279 03-11-23, 09:41 PM
آخر رد: Adel27213
  مشكلة عند الاتصال ب sql server 2014 bassant 1 1,003 27-08-23, 12:26 PM
آخر رد: رضوان الجماعي
  [سؤال] عدم إظهار الصور مع النص فى Listview من قاعدة البيانات alims 2 1,577 27-08-23, 12:22 PM
آخر رد: رضوان الجماعي
  [SQL] استفسار عن طريقة تحزم قواعد بيانات MSSQL مع البرنامج VB.NET2019 salemq 2 528 18-05-23, 03:02 AM
آخر رد: سعود
  استفسار عن تخزين الوقت في قاعدة البيانات strongriseman 2 1,126 22-04-22, 07:27 PM
آخر رد: strongriseman
  [سؤال] مشكلة فى عرض الصورة من ادخل قاعدة البيانات alims 2 1,258 17-11-21, 10:09 AM
آخر رد: سعود
  طريقة الضم LEFT JOIN متعددة بسام محمدغانم 11 2,070 07-11-21, 09:10 AM
آخر رد: Anas Mahmoud
  استعلام يرجع اسماء الاعمدة و نوع البيانات في جدول معين بسام محمدغانم 0 959 23-10-21, 01:43 AM
آخر رد: بسام محمدغانم
  مشكلة عند الاتصال ب sql server 2014 bassant 4 1,412 16-09-21, 02:52 PM
آخر رد: asemshahen5
  الحفظ فى قاعدة البيانات اسلام الكبابى 10 2,342 06-09-21, 06:52 PM
آخر رد: اسلام الكبابى

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم