How to build client-server sql server application?

newdbo

Active member
Joined
Aug 23, 2009
Messages
25
Programming Experience
Beginner
Dear all, i'm newbie in this programming and i dont know whether i post this thread in correct topic, correct me if i'm wrong..i need some references or a starting guide to build an sql server and vb.net application. Please, any help appreciated..
thanks in advance
 
MySQL?
If so, use this:
MySQL :: Connector/Net 6.1
Install, and then add in reference [it's either a com or .net reference] MySQL.Data
Then import at the top of your class
VB.NET:
Imports MySql.Data.MySqlClient
To connect, put this at the top of your class
VB.NET:
    Dim conn As New MySqlConnection
Then, in a sub, put this
VB.NET:
        conn = New MySqlConnection()
        conn.ConnectionString = "Server=127.0.0.1;Database=database;Uid=user;Pwd=password;"
        Try
            conn.Open()
            Label1.Text = "MySQL is CONNECTED!"
            conn.Close()
        Catch ex As Exception
            Label1.Text = "MySQL is NOT CONNECTED! [ERROR]"
        End Try
Label1 Will tell you if you are connected or not.
Edit the username/database/etc in the connection string, but do NOT change the format of the string.

Now, if you want to run a query...
Put this at the top of the class, right below Dim conn:
VB.NET:
    Dim myData As New DataSet
    Dim myAdapter As New MySqlDataAdapter
VB.NET:
        Try
            conn.Open()
            Dim Query As String = "SELECT * from table;"
            Dim da As New MySqlDataAdapter(Query, conn)
            Dim ds As New DataSet()
            If da.Fill(ds) Then
                DataGridView1.DataSource = ds.Tables(0)
            End If
            conn.Close()
        Catch ex As Exception
            Label1.Text = "MySQL [ERROR]"
        End Try
You will need a dataset to return the selected information.
If you want to run a insert/update query then:
VB.NET:
        Try
            conn.Open()

            Dim Query As String
            Query = "UPDATE table set id = 1;"

            Dim dlgRes As DialogResult
            dlgRes = MessageBox.Show( _
                  "Are you sure you want to run this query?: " & Query, _
                  "Yes No", _
            MessageBoxButtons.YesNo, _
                  MessageBoxIcon.Question)

            If dlgRes = DialogResult.Yes Then
                Dim cmd As New MySqlCommand
                cmd = conn.CreateCommand
                cmd.CommandText = Query
                Dim check = cmd.ExecuteReader.RecordsAffected()
                If check > 0 Then
                    MsgBox("Update query successful!")
                Else
                    MsgBox("Update query FAILED!")
                End If
            End If
            conn.Close()
        Catch ex As Exception
            Label1.Text = "MySQL [ERROR]"
        End Try
There's your starting tutorial, GL and HF.
 
Back
Top