C#连接查询数据库
来源:互联网 发布:乡村旅游数据去哪里找 编辑:程序博客网 时间:2024/06/05 09:06
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
namespace 数据库学习
{
class Program
{
static void Main(string[] args)
{
//使用轻量级的SqlDataReader显示数据
//指定Sql Server提供者的连接字符串
string connString = "server=192.168.99.45;database =northwind;uid =sa;pwd=1";
//建立连接对象
SqlConnection Sqlconn = new SqlConnection(connString);
//打开连接
Sqlconn.Open();
////为上面的连接指定Command对象
//SqlCommand thiscommand = Sqlconn.CreateCommand();
//thiscommand.CommandText = "select customerID,companyName from customers";
////为指定的command对象执行DataReader
//SqlDataReader thisSqlDataReader = thiscommand.ExecuteReader();
////只要有数据
//while (thisSqlDataReader.Read())
//{
////输出数据
// Console.WriteLine("\t{0}\t{1}", thisSqlDataReader["customerId"], thisSqlDataReader["companyName"]);
//}
////关闭读取
//thisSqlDataReader.Close();
////关闭连接
//Sqlconn.Close();
//Console.ReadLine();
//使用dataset显示数据
// 查询字符串
string thisCommand = "select customerID,companyName from customers";
//创建SqlDataAdapter对象,有两个参数,一个是查询字符串,一个是连接对象
SqlDataAdapter SqlDap = new SqlDataAdapter(thisCommand,Sqlconn);
//创建DataSet对象
DataSet thisDataset = new DataSet();
//使用SqlDataAdapter的Fill方法填充DataSet,有两个参数,一个是创建的DataSet实例,一个是填入的表
SqlDap.Fill(thisDataset, "customers");
//显示查询结果
foreach (DataRow theRow in thisDataset.Tables["customers"].Rows)
{
Console.WriteLine(theRow["customerID"] + "\t" + theRow["companyName"]);
}
Sqlconn.Close();
Console.ReadLine();
}
}
}
- C#连接查询数据库
- C#连接mysql数据库,并查询,C#查询mysql数据库
- C#连接MYSQL数据库并进行查询
- C#连接MYSQL数据库并进行查询
- C#连接MYSQL数据库并进行查询
- C# , SQL 数据库 -------------- 连接查询和分组查询 ---- (上机练习)
- C#中利用ADO.NET连接和查询SQL数据库
- C# 操作 MySQL 数据库(连接,查询,插入)
- C#与数据库之间的连接(查询,修改,删除,添加)
- 浅析C#如何连接数据库实现查询功能
- 数据查询基础和C#连接数据库语句
- C#学习—连接数据库通用增删改,查询
- C#连接Oracle数据库(直接引用dll使用),查询数据
- C#通过SqlConnection连接查询更新等操作Sqlserver数据库
- C# 连接 access 查询
- 数据库模糊查询+连接查询
- 数据库的连接查询
- 连接数据库查询手册
- 树状数组实践-HIT经理的烦恼
- Netfilter/Iptables入门
- C++ Primer 5e chapter 9.2
- linux下如何打开core dump
- Sencha Touch自定义NavigationView
- C#连接查询数据库
- Codeforces Round #286 (Div. 2) D. Mr. Kitayuta's Technology 强连通分量 有向图求环
- 遇到的几个关于路径报错的问题
- 大论文实验参考资料笔记
- 黑马程序员--正则表达式
- unity3d中,脚本的相互调用。
- Posix信号灯
- 谈谈Android App运行时文件系统路径问题
- JUnit 执行顺序