2011-06-23 7 views
0

私が選択する場所field.table =」+ fooの使用しています;。クエリ、およびデータを全く返さないを理由として混乱ここまで呼び出されdatareaderはパラメータで空に戻りますか?

public Submission GetSubmissionsByID(string x) 
{ 


     string viewQuery = "SELECT Submission.SubmissionId, Submission.CustId, Submission.BroId, Submission.Coverage, Submission.CurrentCoverage, Submission.PrimEx, Submission.Retention, Submission.EffectiveDate, Submission.Commission, Submission.Premium, Submission.Comments FROM Submission WHERE Submission.SubmissionId =" + x; 
     string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString; 
     using (SqlConnection conn = new SqlConnection(connectionString)) 
     { 
      conn.Open(); 

      SqlCommand viewCmd = new SqlCommand(viewQuery, conn); 
      SqlDataReader dr = null; 
      dr = viewCmd.ExecuteReader(); 
      Submission tempSubmission = new Submission(); 

      tempSubmission.SubmissionId1 = dr.GetInt32(0); 
      tempSubmission.CustomerId1 = dr.GetInt32(1); 
      tempSubmission.BrokerId1 = dr.GetInt32(2); 
      tempSubmission.Coverage1 = dr.GetInt32(3); 
      tempSubmission.CurrentCoverage1 = dr.GetInt32(4); 
      tempSubmission.PrimEx1 = dr.GetInt32(5); 
      tempSubmission.Retention1 = dr.GetInt32(6); 
      tempSubmission.EffectiveDate1 = dr.GetDateTime(7); 
      tempSubmission.Commission1 = dr.GetInt32(8); 
      tempSubmission.Premium1 = dr.GetInt32(9); 
      tempSubmission.Comment1 = dr.GetString(10); 

      return tempSubmission; 
     } 
} 

を、照会値Xが有効である場合、上のデータと。その行はまた、一定/有効な値にXを設定して失敗した。

string x = Request.QueryString["SubmissionId"]; 

    SubmissionService ss = new SubmissionService(); 
    Submission sub = ss.getSubmissionByID(x); 
+0

viewQueryはどのようなものに見えるん連結後? – gbn

答えて

3

あなたが最初のレコードに進めるためにRead()を呼び出す必要があります。

 dr = viewCmd.ExecuteReader(); 
     if(dr.Read()) 
     { 
     Submission tempSubmission = new Submission(); 

     tempSubmission.SubmissionId1 = dr.GetInt32(0); 
     tempSubmission.CustomerId1 = dr.GetInt32(1); 
     tempSubmission.BrokerId1 = dr.GetInt32(2); 
     tempSubmission.Coverage1 = dr.GetInt32(3); 
     tempSubmission.CurrentCoverage1 = dr.GetInt32(4); 
     tempSubmission.PrimEx1 = dr.GetInt32(5); 
     tempSubmission.Retention1 = dr.GetInt32(6); 
     tempSubmission.EffectiveDate1 = dr.GetDateTime(7); 
     tempSubmission.Commission1 = dr.GetInt32(8); 
     tempSubmission.Premium1 = dr.GetInt32(9); 
     tempSubmission.Comment1 = dr.GetString(10); 

     return tempSubmission; 
     } 
     return null; 
+0

私のために、もう一つの驚きの瞬間。ありがとう、@Bala。 –

関連する問題