Discord Server TwitterDonation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
mysql chat application
#1
Source code will be coming soon 

what need 2 textboxes

2 buttons

1 timer

demo project will be posted

in 12:00am tonight  
Reply
#2
here is source code for vb.net mysql chat app


Imports MySql.Data.MySqlClient
Imports System
Imports System.Security.Cryptography

Imports System.Net
Imports System.Text
Imports System.Text.RegularExpressions
Imports System.IO
Imports System.Data.SqlClient


Public Class Form1

    Public Function mysqlconnection() As MySqlConnection
        'return new connection.
        Return New MySqlConnection("server=servername; user id=username; password=serverpassword; database=databasename")

    End Function



    Public con As MySqlConnection = mysqlconnection()

    'declaring the variables string
    Public sql As String
    Public result As String

    'declaring the classes
    Dim cmd As New MySqlCommand
    Public dt As New DataTable
    Public da As New MySqlDataAdapter

    Private Sub Chat(ByVal sqlQuery As String)
        Try
            'OPENING THE CONNECTION
            con.Open()
            'HOLDS THE DATA TO BE EXECUTED
            With cmd
                .Connection = con
                .CommandText = sqlQuery
            End With
            'EXECUTE THE DATA
            result = cmd.ExecuteNonQuery
            'CHECKING IF THE DATA HAS BEEN EXECUTED OR NOT
            If result = 1 Then
                MsgBox("message has been sent")
            Else
                MsgBox("Failed to register the user.")
            End If
            con.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click


        sql = "INSERT INTO `chat` (`chat_text`) VALUES ('" _
            & TextBox2.Text & "' )"



    
        Chat(sql)

    End Sub
  

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

        Dim conn As MySqlConnection

        conn = New MySqlConnection
        conn.ConnectionString = ("server=45.32.168.102; user id=newuser; password=password; database=user_register")

        Try
            conn.Open()
        Catch myerror As MySqlException
            MsgBox("No connection")
        End Try

        Dim myAdaptor As New MySqlDataAdapter

        Dim sqlquery = "SELECT * FROM `chat` ORDER BY `chat_text` ASC"
        Dim myCommand As New MySqlCommand()
        myCommand.Connection = conn
        myCommand.CommandText = sqlquery

        myAdaptor.SelectCommand = myCommand
        Dim myData As MySqlDataReader
        myData = myCommand.ExecuteReader()

        Dim sb As StringBuilder = New StringBuilder()
        While myData.Read()
            sb.AppendLine(myData("chat_text"))
        End While
        TextBox1.Text = sb.ToString



       


        myData.Close()
        conn.Close()

    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Button2.PerformClick()
    End Sub


    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Timer1.Interval = 1000
        Timer1.Enabled = True
        Timer1.Start()
    End Sub


End Class
Reply
#3
thank you buddy, nice one, but why you don't make a tut about "How to use your codes?" Wink

[Image: 0yaXvcy.gif]
We Are Anonymous, We Are Legion, We Do not Forgive, We do not Forget
Expect Us
Reply
#4
I though i can do TUT about this maybe.
[Image: b37CyeC.gif]
Reply
#5
(08-22-2017, 12:23 AM)DarkCode Wrote: I though i can do TUT about this maybe.

good so let's see Tongue

[Image: 0yaXvcy.gif]
We Are Anonymous, We Are Legion, We Do not Forgive, We do not Forget
Expect Us
Reply




Users browsing this thread: 2 Guest(s)