Post: [C#] Log/Retrieve Customer Information For Your Services
02-05-2015, 01:30 AM #1
jagex
Gym leader
(adsbygoogle = window.adsbygoogle || []).push({}); *You need to create a mysql database to use this. Its really easy!

1. Create a WinForms Application
2. Add a DataGrid and call it dataGrid
3. Add a reference to MySql
4. Create a class called MySql

Add this to your MySql Class:

It is safer to fetch the connection string from where else instead of hard coding it in!
    
public static void Connect()
{

try
{
MySqlConnection connect = new MySqlConnection("Server=" + "server" + ";" +
"Database=" + "databasename" + ";" +
"Uid=" + "username" + ";" +
"Pwd=" + "password" + ";");
connect.Open();


}
catch (MySqlException ex)
{
MessageBox.Show(ex.Message)
}
}



    
public static void CustomerInformation(DataGridView dataGrid)
{
string cmdAll = "SELECT * FROM (TableName)"; (* means ALL)
MySqlDataAdapter dataAdapter = new MySqlDataAdapter(cmdAll, connect);
DataTable dataTable = new DataTable();
dataAdapter.Fill(dataTable);
dataGrid.DataSource = dataTable;

}
}


Add a timer to your Form1

    
private void Form1_Load(object sender, EventArgs e)
{

MySQL.Connect();
MySQL.CustomerInformation(dataGrid);
timer_GridUpdate.Interval = 100000;
timer_GridUpdate.Start();

}


    
private void timer_GridUpdate_Tick(object sender, EventArgs e)
{
MySQL.CustomerInformation(dataGrid);


}


*I did not add any of mysql exception checks in this tutorial so make sure you add them
Source: You must login or register to view this content.
(Source is very incomplete so don't expect much out of it lol)

Video:
Last edited by jagex ; 02-05-2015 at 01:44 AM.

The following 2 users say thank you to jagex for this useful post:

BISOON, Cyb3r
02-05-2015, 08:59 AM #2
Cyb3r
NextGenUpdate Elite
I could use this with my VB database, testing now thanks. :p
02-05-2015, 09:51 AM #3
Cyb3r
NextGenUpdate Elite
Well i have tried but you forgot to mention that i have to install Mysql class library, here's the link to it: You must login or register to view this content.

I have tried multiple times but i never succeeded, i don't get any sign if the project is working or not, even the labels isn't changing, have you tried your project? it has the same problem as mine.

Thanks anyway. Smile
02-05-2015, 02:53 PM #4
jagex
Gym leader
Yes, I tested my project and it works fine. Watch the video.

Not sure what you are doing wrong unless I can see your code.

Try enabling inner exceptions and see if you get any errors or you can send me your project.
Last edited by jagex ; 02-05-2015 at 02:58 PM.
02-16-2015, 05:34 PM #5
Mr Smithy x
Former Staff
i usually set up an api with php to do all the work and have the c# app use post cmds, and get cmds, i just find it unsafe if my client logs into my mysql db from time to time lol. Nice tutorial btw Happy
02-16-2015, 06:38 PM #6
Default Avatar
Oneup
Guest
Originally posted by Mr
i usually set up an api with php to do all the work and have the c# app use post cmds, and get cmds, i just find it unsafe if my client logs into my mysql db from time to time lol. Nice tutorial btw Happy


That's why you set up a limited user and do everything through stored procedures.
However services are just fine.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo