如何在UWP中连接到MS SQL服务器 [英] How to connect to a MS SQL Sever in UWP

查看:62
本文介绍了如何在UWP中连接到MS SQL服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在标准的cs winforms / asp.net应用程序上,我可以使用System.Data.SqlConnection连接到我的服务器,例如:

 

列表<视频> rv = new List< Video>();
using(SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();

SqlCommand command = new SqlCommand(String.Format(" SELECT * FROM Video"),
connection);
SqlDataReader reader = command.ExecuteReader();


while(reader.Read())
{
IDataReader record = reader;
string name = String.Format(" {0}",record [0])。Trim();
string id = String.Format(" {0}",record [1])。Trim();
string src = String.Format(" {0}",record [2])。Trim();
string metaData = String.Format(" {0}",record [3])。Trim();
string discription = String.Format(" {0}",record [4])。Trim();
string datePosted = String.Format(" {0}",record [5])。Trim();
string status = String.Format(" {0}",record [6])。Trim();
string privateHiden = String.Format(" {0}",record [7])。Trim();
string views = String.Format(" {0}",record [8])。Trim();



视频视频=新视频(name,id,datePosted,metaData,discription,src,status,privateHiden,views);
rv.Add(视频);

}
reader.Close();

返回列表。


有没有办法在通用窗口中使用它?

解决方案

UWP中不存在数据读取器,数据集,sqlconnection等Ado.Net之类的东西。  您可以将实体框架用于SQLite数据库。  如果要连接到Sql Server,则需要通过Web服务进行。




On a standard cs winforms/asp.net application I can use System.Data.SqlConnection to connect to my server something like:

List<Video> rv = new List<Video>(); using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand command = new SqlCommand(String.Format("SELECT * FROM Video"), connection); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { IDataReader record = reader; string name = String.Format("{0}", record[0]).Trim(); string id = String.Format("{0}", record[1]).Trim(); string src = String.Format("{0}", record[2]).Trim(); string metaData = String.Format("{0}", record[3]).Trim(); string discription = String.Format("{0}", record[4]).Trim(); string datePosted = String.Format("{0}", record[5]).Trim(); string status = String.Format("{0}", record[6]).Trim(); string privateHiden = String.Format("{0}", record[7]).Trim(); string views = String.Format("{0}", record[8]).Trim(); Video video = new Video(name, id, datePosted, metaData, discription, src, status, privateHiden, views); rv.Add(video); } reader.Close();

To return a list.

Is there any way to use this in universal windows?

解决方案

None of the Ado.Net stuff like data readers, data set, sqlconnection, etc exist in UWP.  You can use entity framework to a SQLite data base.  If you want to connect to a Sql Server you need to do it through a web service.


这篇关于如何在UWP中连接到MS SQL服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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