webservice直接连接数据库

wuwenzhe 2012-11-28 04:14:51
从网上找到的都是网站添加web服务引用之后,连接数据库的工作都是网站完成的,有没有webservice直接连接数据库的例子?
...全文
1331 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
AlexChowKey 2012-11-29
  • 打赏
  • 举报
回复
在webservice中用jdbc连接就可以了 http://download.csdn.net/detail/chow__zh/4819692这里有实例代码,连接mysql的 下载解压直接使用
心梦缘-雪雁 2012-11-28
  • 打赏
  • 举报
回复
我写的这个是一个级联的案例 你看下吧
心梦缘-雪雁 2012-11-28
  • 打赏
  • 举报
回复
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using System.Data; using System.Data.SqlClient; namespace ClothMSN { /// <summary> /// ShopService 的摘要说明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。 [System.Web.Script.Services.ScriptService] public class ShopService : System.Web.Services.WebService { [WebMethod] public string HelloWorld() { return "Hello World"; } [WebMethod] public string[] getNames(string prefixText, int count) { SqlConnection conn = new SqlConnection("server=.;database=ClothMSN;integrated security=True"); SqlDataAdapter sda = new SqlDataAdapter("select * from goodInfo where goodName like '%" + prefixText + "%'", conn); DataTable dt = new DataTable(); sda.Fill(dt); string[] names = null; if (dt.Rows.Count > 0) { names = new string[dt.Rows.Count]; for (int i = 0; i < dt.Rows.Count; i++) { names[i] = dt.Rows[i][1].ToString(); } } else { names = new string[] { "未查找到对应的记录" }; } return names; } } }
hard_learner 2012-11-28
  • 打赏
  • 举报
回复
你随便找本稍微正规讲解webservice的应该都有讲解,如果是自己写的webservice的话连接数据库的操作是在webservice中的,你看的可能是编写的网站使用第三方公开的webservice接口,顺便建议,如果你是新接触webservice的话不如学习wcf,呵呵

12,162

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧