5 messages in com.mysql.lists.dotnetRe: Getting started| From | Sent On | Attachments |
|---|---|---|
| nil...@aon.at | 12 Feb 2005 13:22 | |
| Jordan Sparks | 12 Feb 2005 13:45 | |
| Sergio Duran | 12 Feb 2005 14:52 | |
| Guy Platt | 12 Feb 2005 23:59 | |
| Sergio Duran | 14 Feb 2005 08:41 |
| Subject: | Re: Getting started![]() |
|---|---|
| From: | Sergio Duran (serg...@gmail.com) |
| Date: | 02/12/2005 02:52:15 PM |
| List: | com.mysql.lists.dotnet |
I personally have been using MySqlHelper. Its pretty easy to use.
On Sat, 12 Feb 2005 13:45:51 -0800, Jordan Sparks <jspa...@free-dental.com> wrote:
If you're using Microsoft Studio or similar, simply look in their help under DataAdapter, DataReader, DataTable, DataConnection, etc. But instead of using the MS version, add a reference to the .NET connector. Put using MySql.Data.MySqlClient; at the top of your file. Change all the examples slightly. Like this:
///<summary>This data adapter is used for all queries to the database.</summary> private MySqlDataAdapter da; ///<summary>This is the connection that is used by the data adapter for all queries.</summary> private MySqlConnection con; ///<summary>Used to get very small bits of data from the db when the data adapter would be overkill. For instance retrieving the response after a command is sent.</summary> private MySqlDataReader dr; ///<summary>Stores the string of the command that will be sent to the database.</summary> private MySqlCommand cmd; ///<summary>After inserting a row, this variable will contain the primary key for the newly inserted row. This can frequently save an additional query to the database.</summary> public int InsertID;
///<summary>Sends a non query command to the database and returns the number of rows affected. If true, then InsertID will be set to the value of the primary key of the newly inserted row.</summary> public int NonQ(string command,bool getInsertID){ cmd.CommandText=command; int rowsChanged=0; try{ con.Open(); rowsChanged=cmd.ExecuteNonQuery(); if(getInsertID){ cmd.CommandText="SELECT LAST_INSERT_ID()";
dr=(MySqlDataReader)cmd.ExecuteReader(); if(dr.Read())
InsertID=PIn.PInt(dr[0].ToString()); } } catch(MySqlException e){ MessageBox.Show("Error: "+e.Message+","+cmd.CommandText); } //catch{ // MessageBox.Show("Error: "+); //} finally{ con.Close(); } return rowsChanged; }
///<summary>Fills table with data from the database.</summary> public DataTable GetTable(string command){ cmd.CommandText=command; DataTable table=new DataTable(); try{ da=new MySqlDataAdapter(cmd); da.Fill(table); } //catch(MySqlException e){ // MessageBox.Show("MySQL Error: "+e.Message); //} catch(MySqlException e){ MessageBox.Show("Error: "+e.Message+","+cmd.CommandText); } finally{ con.Close(); } return table; }
Jordan Sparks
-----Original Message----- From: nil...@aon.at [mailto:nil...@aon.at] Sent: Saturday, February 12, 2005 1:23 PM To: dot...@lists.mysql.com Subject: Getting started
Hi everybody!
Now it's time for me, to get started with .NET Connector.
I hoped, that anyone of you could give me some hints. I mean, I really know nothing :(
How can I connect to a mysql database? I heared something from connection strings and execute non query. But an example would be nice.
Please help me and post a working example, I can work with!
Thank you very much, and sorry for my bad english. Greetings from Austria Gerrit
-- MySQL on .NET Mailing List For list archives: http://lists.mysql.com/dotnet To unsubscribe: http://lists.mysql.com/dotnet?unsub=jspa...@free-dental.com
-- MySQL on .NET Mailing List For list archives: http://lists.mysql.com/dotnet To unsubscribe: http://lists.mysql.com/dotnet?unsub=serg...@gmail.com




