Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

RE: Proper way of retrieving an ?id via .net connection 5x on mysql

From: Peter de Bruine <p.debruine(at)giscare.nl>
Date: Wed Sep 19 2007 - 02:33:27 EDT


Hi Louie,

You should add the parameter to the command like this:

 id=mirandajs;password=dba05pdx;");
 conn.Open();
 MySqlCommand comm = new MySqlCommand("LOCK TABLES profile WRITE", conn);  comm.ExecuteNonQuery();

 comm = new MySqlCommand(String.Format("SELECT * from profile where id = ?id"), conn);  

 //Add parameter
 comm.Parameters.Add("?id", searchId);  

 MySqlDataReader reader = comm.ExecuteReader();

 int otherId = reader.GetInt32("some-other-id");

But your example is very strange you are trying to get an id while you already have that id?? That's not really neccesary.

Do you need help?X

Regards
Peter

-----Oorspronkelijk bericht-----
Van: Louie Miranda [mailto:lmiranda@gmail.com] Verzonden: woensdag 19 september 2007 5:47 Aan: dotnet@lists.mysql.com
Onderwerp: Proper way of retrieving an ?id via .net connection 5x on mysql

I am having problems retrieving ?id, error is always parameter is not defined..

MySqlConnection conn = new
MySqlConnection("server=192.168.10.10;database=test;user
> id=mirandajs;password=dba05pdx;");
> conn.Open();
> MySqlCommand comm = new MySqlCommand("LOCK TABLES profile WRITE",
> conn); comm.ExecuteNonQuery();
>
> comm = new MySqlCommand(String.Format("SELECT * from profile where id
> = ?id"), conn); MySqlDataReader reader = comm.ExecuteReader();
>
> int retrievedId = reader.GetInt32("id"); //comm.Parameters.Add("?id",
> retrievedId);
>
> comm.Parameters.Add("id", MySqlDbType.Int32).Value = retrievedId.id;
>
> DataTable myDataTable = new DataTable(); myDataTable.Load(reader);
> reader.Close();
>
> DetailsView1.DataSource = myDataTable; DetailsView1.DataBind();
> DetailsView1.Dispose();
>
> comm = new MySqlCommand("UNLOCK TABLES", conn);
> comm.ExecuteNonQuery(); conn.Close();
> DetailsView1.Dispose();
>

*Exception Details: *MySql.Data.MySqlClient.MySqlException: Parameter '?id' must be defined.

*Source Error:*

  Line 32:
Line 33: comm = new MySqlCommand(String.Format("SELECT * from profile where id = ?id"), conn);

Line 34:         MySqlDataReader reader = comm.ExecuteReader();
Line 35:
Line 36:         //int retrievedId = reader.GetInt32("id");

How can i properly add the parameter on this? Please help!

-- 
Louie Miranda (lmiranda@gmail.com)
http://www.axishift.com

Security Is A Series Of Well-Defined Steps
chmod -R 0 / ; and smile :)


-- 
MySQL on .NET Mailing List
For list archives: 
http://lists.mysql.com/dotnet
To unsubscribe:    
http://lists.mysql.com/dotnet?unsub=lists@pantek.com
Received on Wed Sep 19 02:34:34 2007
Do you need more help?X

This archive was generated by hypermail 2.1.8 : Sun Oct 07 2007 - 10:15:42 EDT


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library