如何将数据从远程计算机的数据库绑定到datagrid? [英] How to bind data to datagrid from database of remote computer?

查看:96
本文介绍了如何将数据从远程计算机的数据库绑定到datagrid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我现在需要从数据库检索数据并将数据绑定到数据网格.

例如,
我有一个表,该表是问题的集合,它存储在远程计算机的数据库(Microsoft SQL Server 2008)中.如何通过Web服务从数据库中检索问题并将其绑定到另一台计算机的数据网格?

从答案中移出

这是Web服务中的代码.从wpr应用程序的datagrid检索时应该返回arraylist或数据集吗?

Hi All,

I''m now need to retrieve the data from database and bind the data to the datagrid.

For example,
I have a table which is a collection of questions and it is stored in the database(Microsoft SQL Server 2008) of remote computer. How can I retrieve the questions from the database through web service and bind it to the datagrid of another computer?

Moved from Answer

This is the codes in the web service. Should I return an arraylist or dataset while I''m retrieving from datagrid of wpr app?

public ArrayList getSurveyList() // method to get questions
{
ArrayList surveyList = new ArrayList();
try
{
string cmdStr = "SELECT * FROM Survey";
SqlCommand cmd = new SqlCommand(cmdStr, conn);
cmd.CommandText = cmdStr;
SqlDataReader reader = cmd.ExecuteReader(); // Execute SQL Statement
while (reader.Read())
{
Survey s = new Survey();
s.questionID = (int)reader["questionID"];
s.question = reader["question"].ToString();
s.questionType = reader["questionType"].ToString();
surveyList.Add(s); // Add data to ArrayList
}
reader.Close();
if (surveyList.Count == 0) // no record found
{
surveyList sl = new surveyList();
sl.code = "_103";
surveyList.Add(sl);
}
}//end try
catch (Exception)
{
Survey s = new Survey();
s.code = "_001"; // no record found
surveyList.Add(f);
}
return surveyList;
}




我现在的问题是如何从Web服务检索数据到WPF应用程序?
请指导我.谢谢.




My question now is how can i retrieve the data from the web service to wpf application?
Please guide me.Thanks.

推荐答案

假设您之前已经在本地计算机上完成了数据库的操作,那么当数据库位于另一台计算机上时,该如何做呢?基本相同,除了需要修改连接字符串以指向该数据库服务器.如果您已经开始执行一些代码,则也可以将它们发布出来,这样对我们有帮助,因此我们可以为您提供更好的建议.
Assuming you have done this before with your database on your local machine, how you do it when the database is in a different machine is basically the same, except that you need to modify your connection string to point to that database server. If you have some codes that you already started doing, it might be helpful to post them as well so we can give a better advice on what you need to do.


这篇关于如何将数据从远程计算机的数据库绑定到datagrid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆