当前位置:网站首页>Self use learning notes - connected and non connected access to database
Self use learning notes - connected and non connected access to database
2022-04-23 17:10:00 【Tomato Warrior】
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;//sql
using System.Data;//ConnectionState
using System.Configuration;// Used to get the string in the configuration file
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//----------
string ConnStr = "server=(local);database=SystemCourse;integrated security=true";
// string ConnStr = System.Configuration.ConfigurationManager
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConnStr;
if(conn.State ==ConnectionState.Closed)
conn.Open();
//----------
string sql = "select * from students";
SqlCommand cmd = new SqlCommand(sql,conn);
// establish Command After the object , You can execute SQL command , After execution, complete and close the data connection , The sample code is as follows .
// cmd.ExecuteNonQuery(); // perform SQL command
//con.Close(); // Close the connection
//----------
SqlDataReader reader = cmd.ExecuteReader();// take sql The statement is sent to sqlconnection, And produce a sqldatareader object
//reader Is read-only , Can't modify data ,reader Read one and release one , You can only move forward, not backward
while (reader.Read())
{
Console.WriteLine(" full name :{0}",reader[2].ToString());
}
reader.Close();
if (conn.State == ConnectionState.Open)
conn.Close();
}
}
}
版权声明
本文为[Tomato Warrior]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230553458195.html
边栏推荐
- Installing labellmg tutorial in Windows
- Interface document yaml
- Go language RPC communication
- The new MySQL table has a self increasing ID of 20 bits. The reason is
- Idea of batch manufacturing test data, with source code
- C语言函数详解
- El cascade and El select click elsewhere to make the drop-down box disappear
- Collect blog posts
- Solution architect's small bag - 5 types of architecture diagrams
- Nodejs reads the local JSON file through require. Unexpected token / in JSON at position appears
猜你喜欢

ACL 2022 | dialogved: a pre trained implicit variable encoding decoding model for dialogue reply generation

org. apache. parquet. schema. InvalidSchemaException: A group type can not be empty. Parquet does not su

VLAN高级技术,VLAN聚合,超级Super VLAN ,Sub VLAN

Nodejs installation and environment configuration

文件操作《二》(5000字总结篇)

Idea of batch manufacturing test data, with source code

Milvus 2.0 质量保障系统详解

C语言函数详解

自定义my_strcpy与库strcpy【模拟实现字符串相关函数】

Nodejs reads the local JSON file through require. Unexpected token / in JSON at position appears
随机推荐
1-5 nodejs commonjs specification
【生活中的逻辑谬误】稻草人谬误和无力反驳不算证明
Clickhouse SQL operation
websocket
[PROJECT] small hat takeout (8)
Nodejs reads the local JSON file through require. Unexpected token / in JSON at position appears
El date picker limits the selection range from the current time to two months ago
Solution architect's small bag - 5 types of architecture diagrams
Nodejs installation and environment configuration
VLAN高级技术,VLAN聚合,超级Super VLAN ,Sub VLAN
Baidu Map Case - Zoom component, map scale component
Detailed explanation of Milvus 2.0 quality assurance system
Some problems encountered in recent programming 2021 / 9 / 8
Preliminary understanding of promse
文件操作《二》(5000字总结篇)
Read a blog, re understand closures and tidy up
Clickhouse - data type
MySQL modify master database
Smart doc + Torna generate interface document
Idea of batch manufacturing test data, with source code