Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

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

From: Louie Miranda <lmiranda(at)gmail.com>
Date: Tue Sep 18 2007 - 23:47:10 EDT


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 :)
Received on Tue Sep 18 23:47:30 2007

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