Mailing List
Home
Forum Home
MySQL General - General MySQL discussion
MySQL++ - Programming with the C++ API to MySQL
MaxDB - Everything about MaxDB, formerly known as SAP DB
ODBC - ODBC with the MySQL Connector/ODBC driver
MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP
Java Help - Mostly related to the MySQL Connector/J driver
Perl - Perl support for MySQL with DBI and DBD::mysql
GUI - MySQL GUI Tools
Announcement
Subjects
Subject: mysql openssl Question
ERROR 1045: Access denied for user: 'root@localhost ' (Using
password: NO)
Update one field with more fields from another table
Subject: Getting Identity after INSERT
ERROR 2002: Can 't connect to local MySQL server through socket
mysql test 4 1 fails with the gis test
Subject: MySQL Cluster Software
Downgrade Mysql from 4 to 3 23
Mysql 4 0 Oracle Stored Procedure Trigger Conversion
Can 't access mysql after kernel upgrade
Executing MySQL Commands From Within C Program
Comparing and writing out BLOBS
Subject: Re: Preventing Duplicate Entries
FULLTEXT query format question
Strange behavior, Table Level Permission
Does the binary log enabling affect the MySQL performances?
mysql:it 's a db not a dbms how it 's possible?!
mysql have same function mthod as Oracle decode()
 
connection

connection

2007-10-17       - By Bonnett, John

 Back
If you are using C#, you are presumably using the .NET framework too. In
that case you probably want the MySQL .NET Connector instead of ODBC.

For instance I have MySQL Connector Net 5.1.3 installed and I add a
reference to MySql.Data.dll into my project. Then I can write code like
this.

   Private Sub LoadIt(ByRef Cbo As System.Windows.Forms.ComboBox)
       Dim ConnStr As String = "Database=MyDatabase;Data
Source=MyHost;User Id=MyUserId;Password=MyPassword"
       Dim Con As MySql.Data.MySqlClient.MySqlConnection = New
MySql.Data.MySqlClient.MySqlConnection(ConnStr)
       Con.Open()
       Dim SQL As String = "SELECT ID, Name FROM Customers"
       Dim Cmd As MySql.Data.MySqlClient.MySqlCommand = New
MySql.Data.MySqlClient.MySqlCommand(Sql, gCon.MySQLConnection)
       Dim rdr As MySql.Data.MySqlClient.MySqlDataReader Cmd.ExecuteReader()

       Cbo.BeginUpdate()
       Cbo.Items.Clear()
       Do While rdr.Read()
           Cbo.Items.Add(New ListBoxItem(rdr.GetValue(1),
CLng(rdr.GetValue(0))))
       Loop
       rdr.Close()
       Cbo.EndUpdate()
       Con.Close()
   End Sub

This code loads a combobox with some information from a database table.
The class ListBoxItem defines objects I use for populating list and
comboboxes. These objects provide some text to display and a long
integer key to link to the database record.

I might add that I do not use the code above anywhere. I just made it up
out of bits of code I have scattered through one of my programs in
various classes. The code is in VB.NET but you should be able to easily
translate it to C#.

Hope this helps.

John Bonnett

-- --Original Message-- --
From: santhosh.vudarla@(protected)
[mailto:santhosh.vudarla@(protected)]
Sent: Wednesday, 17 October 2007 1:06 PM
To: myodbc@(protected)
Subject: connection




HI
I want to connect the MySql through c#, for that i download Odbc
connector from MySql.
How to connect it
I want some sample code to connect the database.
canu help me please ....








Regards
Santhosh Vudarla




--
MySQL ODBC Mailing List
For list archives: http://lists.mysql.com/myodbc
To unsubscribe:    http://lists.mysql.com/myodbc?unsub=mysql@(protected)