数据库|mysql教程
silverlight,WCF,访问,SQLserve
数据库-mysql教程
百度定位 源码,vscode调试在哪,ubuntu opnfv,tomcat 访问原理,sqlite字符集法语,华为网盘discuz插件 5.0.0,国内现在流行的前端框架,高端智能化网络爬虫,php 获取首字母,新手做seo文章,php 行业网站,仿qq音乐网页版源码,关于我们 页面模板lzw
VS+sql+win8.1测试通过 作者:一剑 1.创建sliverlight项目testWCFsql; 2.右击web项目添加新建项-类,命名为ClassDBserver,修改代码: using System.Data; using System.Data.SqlClient; using System.Web.Configuration; namespace testWCFsql.Web{
小号交易源码,vscode 显示完整路径,ubuntu 终端停止,tomcat目录定时重启,爬虫 简书,php文件另存为,黄石品牌seo推广哪家好,医院诊所网站源码,ecshop 最好的模板lzw
好东西源码分享解压密码,vscode 导出war包,ubuntu 音质差,tomcat接收文件,爬虫 class,win8 iis php,宁德市seo厂家,最新目录分类网站源码,js 背景特效模板下载lzw
VS+sql+win8.1测试通过 作者:一剑
1.创建sliverlight项目testWCFsql;
2.右击web项目添加新建项->类,命名为ClassDBserver,修改代码:
using System.Data;using System.Data.SqlClient;using System.Web.Configuration;namespace testWCFsql.Web{ public class ClassDBserver { static public DataSet DBselect(string sql) { string conn; conn = "Data Source=none;Initial Catalog=comDB;User ID=sa;Password=123456"; //conn = WebConfigurationManager.AppSettings.Get("DBappSettings"); //conn = WebConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString; try {using (SqlConnection cnn = new SqlConnection(conn)){ cnn.Open(); using (SqlTransaction trans = cnn.BeginTransaction(IsolationLevel.Serializable)) { try { using (SqlCommand cmd = new SqlCommand(sql, cnn)) {cmd.Transaction = trans;using (DataSet ds = new DataSet()){ using (SqlDataAdapter da = new SqlDataAdapter(cmd)) { da.Fill(ds); mit(); } return ds;} } } catch (Exception ex) { trans.Rollback(); return new DataSet(); throw ex; } finally { } }} } catch (Exception ex) {return new DataSet();throw ex; } } }}
3.右击testWCFsql.web项目添加新建项“启用了Silverlight的WCF服务”,命名为ServiceWCF;
4.修改
[OperationContract]public void DoWork(){ return; }
为
using System.Data;using System.Collections.Generic;[OperationContract]public List getData(){ DataSet ds = ClassDBserver.DBselect("select * from employee"); List userList = new List();//添加using System.Collections.Generic; foreach (DataRow dr in ds.Tables[0].Rows) { ClassEmployee user = new ClassEmployee();//userList是引用类型,所以这句不能放foreach外面 user.ID = (int)dr["ID"]; user.name = (string)dr["name"]; user.departmentID = (int)dr["departmentID"]; userList.Add(user); } return userList;}[DataContract]public class ClassEmployee{ [DataMember] public int ID; [DataMember] public string name; [DataMember] public int departmentID;}
5.生成一下;
6.右击客户端testWCFsql项目,添加服务引用->发现,默认ServiceReference1,确定;
7.双击页面文件MainPage.xaml.cs,从工具箱中拖入DataGrid控件,命名为datagrid1;
8.修改后台代码为:
using System.Xml;using System.IO;namespace testWCFsql{ public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); ServiceReference1.ServiceWCFClient myClient = new ServiceReference1.ServiceWCFClient(); myClient.getDataCompleted += new EventHandler(myGetDataCompleted); myClient.getDataAsync(); } void myGetDataCompleted(object sender, ServiceReference1.getDataCompletedEventArgs e) { System.Collections.ObjectModel.ObservableCollection users = e.Result; datagrid1.ItemsSource = users; } }}
9.此步可选:双击Weg.config修改,在
之间插入
"DBappSetting" value="Data Source=none;Initial Catalog=comDB;User ID=sa;Password=123456"/> "myConnectionString" connectionString="Data Source=none;Initial Catalog=comDB;User ID=sa;Password=123456" providerName="System.Data.SqlClient"/>
同时修改前面ClassDBserver.cs中的连接字符串为从配置文件中读取。
10.Now,just run it!!