2010-03-30 34 views
1

語法。我正在使用C#MYsql的。我有查詢,如果我對MySQL工作臺投放效果,但在C#它不返回任何值,也沒有給螞蟻錯誤too.There只有一個不同使用MySQL的我以前的表名databaseName.tableName使用,但在C#中,我認爲它不`噸必要。 這是查詢不返回任何內容的一部分。MySQL的:使用C#

編輯:解決

"(select Lesson_Name from schedule where Group_NO = (select Group_NO from sinif inner join student ON sinif.Group_ID=student.Group_ID where Student_Name=(?Student))"+ 
      " And Day_Name =(select Day_Name from day inner join date ON day.Day_ID=date.DayName where Date=(?Date))" + 
      "And Lesson_Time= (select Lesson_Time from clock where Lesson_Time <= (?Time)order by Lesson_Time DESC limit 0, 1) " + 
      " And Week_NO = (select Week_NO from week inner join date ON week.Week_ID=date.Week_ID where Date=(?Date))) 

,在這裏它執行時,用戶點擊按鈕的所有代碼。

private void check_B_Click(object sender, EventArgs e) 
    { 

     connection.Open(); 

     for (int i = 0; i < existingStudents.Count; i++) 
     { 
      MySqlCommand cmd1 = new MySqlCommand("select Student_Name,Student_Surname,Student_MacAddress from student ", connection); 
      MySqlCommand cmd2 = new MySqlCommand("insert into check_list (Student,Mac_Address,Date,Time,Lesson_Name)"+ 
      "values((?Student),(?MacAddress),(?Date),(?Time),"+ 
      "(select Lesson_Name from schedule where Group_NO = (select Group_NO from sinif inner join student ON sinif.Group_ID=student.Group_ID where Student_Name=(?Student))"+ 
      " And Day_Name =(select Day_Name from day inner join date ON day.Day_ID=date.DayName where Date=(?Date))" + 
      "And Lesson_Time= (select Lesson_Time from clock where Lesson_Time <= (?Time)order by Lesson_Time DESC limit 0, 1) " + 
      " And Week_NO = (select Week_NO from week inner join date ON week.Week_ID=date.Week_ID where Date=(?Date))))", connection); 

      MySqlParameter param1 = new MySqlParameter(); 
      param1.ParameterName = "?Student"; 
      reader = cmd1.ExecuteReader(); 
      if (reader.HasRows) 
       while (reader.Read()) 
       { 
        if (reader["Student_MacAddress"].ToString() == existingStudentsMac[i].ToString()) 
         param1.Value = reader["Student_Name" ]+" "+reader["Student_Surname"]; 
       } 

      reader.Close(); 

      MySqlParameter param2 = new MySqlParameter(); 
      param2.ParameterName = "?MacAddress"; 
      param2.Value = existingStudentsMac[i]; 

      MySqlParameter param3 = new MySqlParameter(); 
      param3.ParameterName = "?Date"; 
      param3.Value = DateTime.Today.Date; 

      MySqlParameter param4 = new MySqlParameter(); 
      param4.ParameterName = "?Time"; 
      param4.Value = DateTime.Now.ToString("HH:mm"); 


      cmd2.Parameters.Add(param1); 
      cmd2.Parameters.Add(param2); 
      cmd2.Parameters.Add(param3); 
      cmd2.Parameters.Add(param4); 

      cmd2.ExecuteNonQuery(); 

     } 


     connection.Close(); 
     MessageBox.Show("Sucsess :)"); 

    } 

回答

0

有着悠久的實驗)),我發現我的mistakes.MySqlParameter參數1具有價值Student_Name,我也加入Student_Surname,但在我的表,只有Student_Name正因爲如此,他們不匹配。也param4.ParameterName = "?Time";是返回系統時間,但具有不同的時間格式。我將它改爲param4.Value=DateTime.Now.ToString("hh:mm"); Alson我認識到,而不是使用Lesson_Time <= (?Time)使用Lesson_Time <= ('?Time')解決了問題。我認爲在我的表中,我定義課程的時間爲一個字符串和('?時間')返回字符串。