Я безуспешно пытался связать gridview через веб-сервис, но ничего не появляется.Что-то не так с моим веб-методом?
Вот что у меня в папке App_Code: membersService.cs, DataAccessService.cs, Post.cs membersService.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;
}
Post.cs:
public class Post
{
public string username;
public string post;
public string postDateTime;
}
Буду признателен за любую помощь, которую я могу получить.Спасибо!