RE: connection

"Bonnett, John" <[email protected]>
Newsgroups gmane.comp.db.mysql.odbc
Message-ID <[email protected]>
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: [email protected]
[mailto:[email protected]] 
Sent: Wednesday, 17 October 2007 1:06 PM
To: [email 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/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.