Click here to Skip to main content
15,888,461 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to compare password from notepad with in the textbox Pin
krajah1027-Mar-07 5:10
krajah1027-Mar-07 5:10 
GeneralRe: How to compare password from notepad with in the textbox Pin
Not Active27-Mar-07 5:16
mentorNot Active27-Mar-07 5:16 
GeneralRe: How to compare password from notepad with in the textbox Pin
krajah1027-Mar-07 5:36
krajah1027-Mar-07 5:36 
GeneralRe: How to compare password from notepad with in the textbox Pin
Christian Graus27-Mar-07 5:42
protectorChristian Graus27-Mar-07 5:42 
GeneralRe: How to compare password from notepad with in the textbox Pin
Not Active27-Mar-07 5:43
mentorNot Active27-Mar-07 5:43 
GeneralRe: How to compare password from notepad with in the textbox Pin
Khoramdin27-Mar-07 5:53
Khoramdin27-Mar-07 5:53 
GeneralRe: How to compare password from notepad with in the textbox Pin
krajah1027-Mar-07 6:03
krajah1027-Mar-07 6:03 
GeneralRe: How to compare password from notepad with in the textbox Pin
Khoramdin27-Mar-07 6:28
Khoramdin27-Mar-07 6:28 
Hello mate,

Windows Applications were never meant to be connected to anythingelse than MS product. But you are in LUCK as there are ways to make your Windows Application work flawlessly with other technologies such as MySQL.

Step 1:
In order for your Windows Application written in C# to get connected to MySQL you need to have the right driver. You can get this from the good old MySQL website. Here is the link to save you the time and the headache looking for it, mate.

http://dev.mysql.com/downloads/connector/odbc/3.51.html[^]

Download and install the right package and then you are ready for Rock & Roll.

Step 2:
Add the following into your C# Windows Application:

private System.Data.Odbc.OdbcConnection OdbcCon; //open connection to server<br />
private System.Data.Odbc.OdbcCommand OdbcCom; //run a query on the database<br />
private System.Data.Odbc.OdbcDataReader OdbcDR; //read the query<br />
private System.Data.Odbc.OdbcDataAdapter OdbcAd; //Create a bridge between the Dataset and data source<br />
private string ConStr;


Step 3:
Now you are ready to talk to your Database, mate. Just talk to your database using MySQL commands. What can be done is simply limited only by your imagination.

Here is a few examples to set you in the right direction.

Example 1: Getting Connected to MySQL database:
private void btnConnect_Click(object sender, EventArgs e)<br />
        {<br />
            ConStr = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=" + txtIP.Text + ";PORT=" + txtPort.Text + ";DATABASE=" + txtDatabase.Text + ";UID=" + txtUsername.Text + ";PWD=" + txtPassword.Text + ";OPTION=3";<br />
            OdbcCon = new System.Data.Odbc.OdbcConnection(ConStr);<br />
            btnListTables.Enabled = true;<br />
<br />
            try<br />
            {<br />
                txtLog.AppendText("Openning connection...\r\n");<br />
                if (OdbcCon.State == ConnectionState.Closed)<br />
                {<br />
                    OdbcCon.Open();<br />
                }<br />
                txtLog.AppendText("Connection opened\r\n");<br />
            }<br />
            catch (System.Data.Odbc.OdbcException Ex)<br />
            {<br />
                txtLog.AppendText(Ex.Message + "\r\n");<br />
                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);<br />
            }<br />
        }<br />


Example 2: Showing all the tables:
private void btnListTables_Click(object sender, EventArgs e)<br />
{<br />
    if (OdbcCon.State == ConnectionState.Open)<br />
    {<br />
        OdbcCom = new System.Data.Odbc.OdbcCommand("SHOW TABLES", OdbcCon);<br />
        OdbcDR = OdbcCom.ExecuteReader();<br />
        txtLog.AppendText("Tables inside " + txtDatabase.Text + ":\r\n");<br />
        while (OdbcDR.Read())<br />
        {<br />
            txtLog.AppendText(">> " + OdbcDR[0] + "\r\n");<br />
        }<br />
    }<br />
}


For some reason you are seeing the words PORT as ";PORT" and PWD as ";PWD" in the above code. Just replace the smily faces with the correct word and you should be alright. You need to place ";" before the word PORT and PWD. I guess ";" + "P" gives the smily face. Smile | :)

By the, my humble apology for the messy codes.

I hope this gets you started.

Khoramdin








-- modified at 12:49 Tuesday 27th March, 2007
QuestionNew workspace window Pin
sinosoidal27-Mar-07 4:15
sinosoidal27-Mar-07 4:15 
AnswerRe: New workspace window Pin
Christian Graus27-Mar-07 4:22
protectorChristian Graus27-Mar-07 4:22 
Questionconnect Dataset with reportviewer Pin
FrankBoonen27-Mar-07 4:10
FrankBoonen27-Mar-07 4:10 
QuestionHow can i rename a file?? Pin
Test27030727-Mar-07 4:10
Test27030727-Mar-07 4:10 
AnswerRe: How can i rename a file?? Pin
Martin#27-Mar-07 4:19
Martin#27-Mar-07 4:19 
QuestionEvent and EventHandler for communication required Pin
Starzfighter27-Mar-07 3:56
Starzfighter27-Mar-07 3:56 
AnswerRe: Event and EventHandler for communication required Pin
Not Active27-Mar-07 5:21
mentorNot Active27-Mar-07 5:21 
QuestionPassing Recordset from C# COM to VBScript Pin
rahvyn627-Mar-07 3:49
rahvyn627-Mar-07 3:49 
Questionend (break) Pin
SVb.net27-Mar-07 3:46
SVb.net27-Mar-07 3:46 
AnswerRe: end (break) Pin
Christian Graus27-Mar-07 3:48
protectorChristian Graus27-Mar-07 3:48 
GeneralI rarely say this Pin
Ennis Ray Lynch, Jr.27-Mar-07 5:13
Ennis Ray Lynch, Jr.27-Mar-07 5:13 
GeneralRe: end (break) Pin
SVb.net28-Mar-07 6:38
SVb.net28-Mar-07 6:38 
QuestionHow could i dispose a windows form. Pin
Test27030727-Mar-07 3:40
Test27030727-Mar-07 3:40 
AnswerRe: How could i dispose a windows form. Pin
Martin#27-Mar-07 3:44
Martin#27-Mar-07 3:44 
GeneralRe: How could i dispose a windows form. Pin
Test27030727-Mar-07 3:53
Test27030727-Mar-07 3:53 
AnswerRe: How could i dispose a windows form. Pin
Christian Graus27-Mar-07 3:48
protectorChristian Graus27-Mar-07 3:48 
GeneralRe: How could i dispose a windows form. Pin
Test27030727-Mar-07 4:06
Test27030727-Mar-07 4:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.