0
웹 서비스를 통해 gridview를 바인딩하는 데 실패했지만 아무 것도 표시되지 않았습니다. 웹 메서드에 문제가 있습니까? 여기 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;
}
내가 얻을 수있는 도움에 감사드립니다. 고맙습니다!
나는 그것을 가지고있다 : 내 질문에 잘못된 것이있다. 도와 주셔서 감사합니다 competent_tech! – jannn