2011-12-08 11 views
0

Webサービスを介してgridviewをバインドしようとして失敗しましたが、何も表示されません。私のWebメソッドに何か問題はありますか?ここでGridview ObjectDataSourceを使用する - 情報を表示しない

は、私は私のApp_Codeフォルダーに持っているものです:membershipService.cs、DataAccessService.cs、Post.cs membershipService.cs:

[WebMethod(Description = "Display all users' post")] 
    public Post[] DisplayAllPosts() 
    { 
     List<Post> usersPosts = new List<Post>(); 
     DataSet ds; 
     Post p; 

     try 
     { 
      ds = DataAccessService.RunSimpleQuery("SELECT username, post, postDateTime FROM UserPosts ORDER BY postID DESC"); 

      foreach (DataRow dr in ds.Tables[0].Rows) 
      { 
       p = new Post(); 
       p.username = dr["username"].ToString(); 
       p.post = dr["post"].ToString(); 
       p.postDateTime = dr["postDateTime"].ToString(); 
       usersPosts.Add(p); 
      }   
      return usersPosts.ToArray(); 
     } 
     catch (Exception ex) 
     { 
      return null; 
     } 
    } 

DataAccessService.cs:

public static DataSet RunSimpleQuery(string query) 
{ 
    DataSet result = new DataSet(); 
    OleDb.OleDbConnection connection = new System.Data.OleDb.OleDbConnection(ConnectionString); 
    OleDb.OleDbCommand command; 
    OleDb.OleDbDataAdapter dataAdapter; 

    try 
    { 
     //open database connection 
     connection.Open(); 

     //create database command for query 
     command = new OleDb.OleDbCommand(); 
     command.CommandText = query; 
     command.Connection = connection; 
     command.CommandType = CommandType.Text; 

     //create data adapter and use it to fill the data set using the command 
     dataAdapter = new OleDb.OleDbDataAdapter(); 
     dataAdapter.SelectCommand = command; 
     dataAdapter.Fill(result); 
    } 
    catch 
    { 
     result = null; 
    } 
    finally 
    { 
     //close connection 
     connection.Close(); 
     connection.Dispose(); 
    } 
    //return dataset 
    return result; 
} 

ポスト。 cs:

public class Post 
{ 
    public string username; 
    public string post; 
    public string postDateTime; 
} 

私は何か助けていただきありがとうございます。ありがとうございました!

答えて

0

DisplayAllPostsの例外ハンドラに例外がスローされているかどうかを確認するためにブレークポイントを設定しようとしましたか?

データベースの列がすべてnull以外の場合を除き、例外をスローしている列の1つにDbNull.Valueがある可能性があります。

+0

私は今すぐ取得しました。クエリに問題がありました。 competent_tech!ありがとうございました! – jannn

関連する問題