+ Reply to Thread
Results 1 to 1 of 1

Thread: mysql join causing exception

  1. #1
    the maya is offline x10Hosting Member the maya is an unknown quantity at this point
    Join Date
    Oct 2009
    Posts
    11

    Smile mysql join causing exception

    Hi Guys,

    I'm hoping someone out there can help me with a little problem I am using a join statement to join 4 tables together. It works fine on my pc with local mysql but when i upload to x10hosting i get an exception error.

    My join statementis:

    cmd = new MySqlCommand("select *, p.nameP, s.SiteName from dates AS d"
    + " join sites AS s on d.SiteID = s.SiteID"
    + " left join people AS p on d.idpeople = p.idpeople"
    + " left join monuments AS m on d.idmonument = m.idmonuments", conn);

    As I say, this works well l,ocally and gives me the results I want. However on x10 i get:

    Server Error in '/' Application

    Array index is out of range.

    Description: HTTP 500. Error processing request.
    Stack Trace:
    System.IndexOutOfRangeException: Array index is out of range.
    at System.Data.Common.DataAdapter.FillTable (System.Data.DataTable dataTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords, System.Int32& counter) [0x00000]
    at System.Data.Common.DataAdapter.FillInternal (System.Data.DataSet dataSet, System.String srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords) [0x00000]
    at System.Data.Common.DataAdapter.Fill (System.Data.DataSet dataSet, System.String srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords) [0x00000]
    at System.Data.Common.DbDataAdapter.Fill (System.Data.DataSet dataSet, Int32 startRecord, Int32 maxRecords, System.String srcTable, IDbCommand command, CommandBehavior behavior) [0x00000]
    at System.Data.Common.DbDataAdapter.Fill (System.Data.DataSet dataSet, System.String srcTable) [0x00000]
    at (wrapper remoting-invoke-with-check) System.Data.Common.DbDataAdapter:Fill (System.Data.DataSet,string)
    at dates.Page_Load (System.Object sender, System.EventArgs e) [0x00000]
    at System.Web.UI.Control.OnLoad (System.EventArgs e) [0x00000]
    at System.Web.UI.Control.LoadRecursive () [0x00000]
    at System.Web.UI.Page.ProcessLoad () [0x00000]
    at System.Web.UI.Page.ProcessPostData () [0x00000]
    at System.Web.UI.Page.InternalProcessRequest () [0x00000]
    at System.Web.UI.Page.ProcessRequest (System.Web.HttpContext context) [0x00000] Version information: Mono Version: 2.0.50727.1433; ASP.NET Version: 2.0.50727.1433


    Any help or suggestions would be greatly appreciated.

    Thx
    Edit:
    forgive a newbies ignorance. I tried the sql statement in phpadmin and it worked! If i had read the error message correc tly it would seem that the error is occurring in the data adapter. code below:

    conn.Open();

    cmd.ExecuteNonQuery();

    sda = new MySqlDataAdapter(cmd);
    ds = new DataSet();
    sda.Fill(ds);

    ListView1.DataSource = ds.Tables[0].DefaultView;
    ListView1.DataBind();

    // close database connection
    conn.Close();

    i have used this same code on other pages without problems. Can anybody suggest anything pls.

    thx.
    Edit:
    more info:

    if i use a simple select statement i.e. select a, b from c it works, no exception problems.
    Edit:
    CRACKED IT!

    was:

    cmd = new MySqlCommand("select *, p.nameP, s.SiteName, m.nameM from dates AS d"
    + " join sites AS s on (d.SiteID = s.SiteID)"
    + " left join people AS p on (d.idpeople = p.idpeople)"
    + " left join monuments AS m on (d.idmonument = m.idmonuments)", conn);

    should be:

    cmd = new MySqlCommand("select d.*, p.nameP, s.SiteName, m.nameM from dates AS d"
    + " join sites AS s on (d.SiteID = s.SiteID)"
    + " left join people AS p on (d.idpeople = p.idpeople)"
    + " left join monuments AS m on (d.idmonument = m.idmonuments)", conn);

    it's a small difference but makes a huge difference. What don't understand is why it worked on my localhost but not on x10. Anyway thats for another day.
    Last edited by the maya; 11-11-2009 at 05:33 PM. Reason: Automerged Doublepost

+ Reply to Thread

Similar Threads

  1. [PHP] MySQL and PHP
    By Bryon in forum Tutorials
    Replies: 43
    Last Post: 03-24-2011, 07:27 AM
  2. MySQL Join
    By jason32 in forum Programming Help
    Replies: 6
    Last Post: 08-01-2009, 08:26 PM
  3. Replies: 14
    Last Post: 09-29-2008, 07:07 PM
  4. New Site-Suggestions?
    By mnoutside in forum Review My Site
    Replies: 9
    Last Post: 08-27-2008, 07:01 AM
  5. Have a problem with my forum
    By tikloos in forum Scripts & 3rd Party Apps
    Replies: 43
    Last Post: 01-19-2006, 01:14 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers