c# - DataReader returns no rows -- rows are present in database -


OK the world, I'm having some trouble, this is not 'homework'

My Have some code that needs to do two things: 1) Read a list of artists from the database - 2) Find all tracks that artist and for next store

What I'm doing I: 1) Select from artists Artists I get my list of artists. I call it list & lt; String & gt; Make this great by using a DataReader etc. in Datatype. 2) Track_numbers tracks as SELECT count (*) WHERE ArtistID = @ ArtistID does not work so great

My problem :
Second The selection statement will be successful if I manually track track_numbers as ArtistID (i.e .: SELECT SELECT SELECT (*) WHERE ArtistID = 0 works) But if I am repeating through my list, it will always return zero results.

I have connector / net 6.3.6 , Visual Studio 2010 (all updates), .NET 4.0 client profiles MySQL Community Server 5.5.9 x 64 , Windows 7 Home Premium x64

I've tried:

  • To construct a string combination
  • Cast casting artist as string, then an integer, then vice-versa
  • rearrange where the parameters are defined , The value has been put in command Ekst

    relevant (I think) code below:

      List & lt; String & gt; List = new list & lt; String & gt; (); Hashtable table = new hashtable (); DbProviderFactory factory = DbProviderFactories.GetFactory (setting.ProviderName); (Using DbConnection conn = factory.CreateConnection ()) (conn.ConnectionString = setting.ConnectionString; conn.Open (); (DbCommand CMD = conn.CreateCommand ()). (CMD Commands Type = CommandType.Text; Cmd.CommandText = "Select Artists from Artists;"; (Using DbDataReader Reader = CMD.Extire Reader ()) {reader.Read ()) {list.Add (Reader ["ArtistID"]. ToString ( )); // This works, and I can not reproduce any problem through this list}}} {DbCommand cmd = conn.CreateCommand ()) using {cmd.CommandType = CommandType.Text; Cmd. CommandText = "Select Count (*) WHERE ArtistID = @ ArtistID; "; //cmd.CommandText =" counting tracks as counting numbers (*) as counted by the track WHERE ArtistID = 0; "; & lt; - This line DbParameter param = cmd.CreateParameter () Works; Param.ParameterName = "@ ArtistID"; foreign (in string artist list) {param.Value = artist; cmd.Parameters.Add (absolute); (DbDataReader Reader = CMD.Extire Reader ()) When using {reader.Read ()} {Console.WriteLine (artist + "\ t" + Reader ["Methane"]]; // Reader ["Count"] always '0'} cmd.Parameters.Clear (); Database table format: A value of the artist / key called  ArtistID , type  int  
    has three columns of Tracks, TrackID (int, pk ) , artist (int) , albumid (int)

    any suggestions? Thank you.

    I think you have to remove cmd.Parameters.Add (param); Call it adds a new parameter on each run, for the current parameter, every time the parameter value should be sufficient to determine.

Comments