博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C# webService 读取txt/Excel/SQL/Orcal的方法
阅读量:5058 次
发布时间:2019-06-12

本文共 1967 字,大约阅读时间需要 6 分钟。

1.  C#读取txt

2.  C#读取Excel

string strOdbcCon = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\Others\\xml data.xlsx; Extended Properties=Excel 8.0"; //定义OleDbConnection对象实例并连接Excel表格

OleDbConnection OleDB = new OleDbConnection(strOdbcCon);

 //定义OleDbDataAdapter对象实例并调用Select查询语句提取Excel数据信息

OleDB.Open();

String strExcel = "select * from[sheet1$] where UserNo="+username;

XmlDocument myXmlDocument = new XmlDocument();

DataSet ds = new DataSet();

OleDbDataAdapter myCommand = new OleDbDataAdapter(strExcel, strOdbcCon);

OleDB.Close();

myCommand.Fill(ds);           

myXmlDocument.LoadXml(ds.GetXml());

return myXmlDocument;

3. C# 读取 SQL

          string sConnect = string.Format("server=***;database=*****");

                string sqlcommand = "select * from [iexec].[dbo].[SAP_Transfer_Log]";

                XmlDocument myXmlDocument = new XmlDocument();

                SqlConnection conn = new SqlConnection(sConnect);

                DataSet DT = new DataSet();

                if ("open" != conn.State.ToString().ToLower())

                {

                    conn.Open();

                }

                SqlCommand MyCommand = new SqlCommand(sqlcommand, conn);

                SqlDataAdapter MyDataAdapter = new SqlDataAdapter(MyCommand);

                MyDataAdapter.Fill(DT);

                conn.Close();

                myXmlDocument.LoadXml(DT.GetXml());

                return myXmlDocument;

4.C#读取Orcal

             DataSet dsNorthwind = new DataSet();

            //Create the connection string.          

             String sConnect;

            sConnect = "Password=eaiuser;User ID=eaiuser;Data Source=eaitest";

            //Create a connection object to connect to the northwind db.

            OracleConnection nwconnect = new OracleConnection(sConnect);

            //Create a command string to select all the customers in the WA region.

            String sCommand = "Select * from users";

            //Create an adapter to load the DataSet.

            OracleDataAdapter myDataAdapter = new OracleDataAdapter(sCommand, nwconnect);

            //Fill the DataSet with the selected records.

            myDataAdapter.Fill(dsNorthwind, "users");

            //Load the document with the DataSet.

            XmlDataDocument doc = new XmlDataDocument(dsNorthwind);

            //Display the XmlDataDocument.

            doc.Save(Console.Out);

转载于:https://www.cnblogs.com/ATS-MES/p/3651827.html

你可能感兴趣的文章
泛型-通配符,受限泛型(上限和下限)
查看>>
Codeforces Round #411 div 2 D. Minimum number of steps
查看>>
超链接标签a样式生效,取消下划线,文字垂直(上下)居中
查看>>
HDU5882
查看>>
Flume入门(一)
查看>>
bootstrap笔记
查看>>
数据库先系统与原理第三章笔记:数据库SQL查询语言
查看>>
Python的方法解析顺序(MRO)[转]
查看>>
Android R.java:10: “duplicate class”
查看>>
双飞翼布局
查看>>
Jmeter实现Dubbo接口测试
查看>>
用qq电脑管家解决他人磳网
查看>>
HashMap使用
查看>>
programming language part b 第一周作业
查看>>
OFbiz--简单介绍
查看>>
输入10个数,求出最大元素是第几个数(数组作为函数參数)
查看>>
百度和谷歌仍有差距
查看>>
部分 CM11 系统 Android 平板执行植物大战僵尸 2 黑屏的解决的方法
查看>>
[ACM] HDU 5025 Saving Tang Monk (状态压缩,BFS)
查看>>
ubuntu-利用pdnsd-TCP方式获取IP-拒绝DNS污染
查看>>