国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

C#對(duì)于sql server數(shù)據(jù)庫(kù)的簡(jiǎn)單操作

2019-11-17 03:12:15
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

C#對(duì)于sql server數(shù)據(jù)庫(kù)的簡(jiǎn)單操作

1.在用windows模式登陸sql server 數(shù)據(jù)庫(kù) 簡(jiǎn)歷一個(gè)student的數(shù)據(jù)庫(kù),然后新建查詢:

create table student( id     int  auto_increment  PRimary key, name char(10) not null, sex    char(10) not null, age   char(10) not null,   )

2.在vs中新建一個(gè)項(xiàng)目,輸入一下代碼:

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Data;using System.Data.SqlClient;namespace Consoleapplication1{    class Program    {        static void Main(string[] args)        {            string connSting;            connSting = "server=localhost;database=student;Integrated Security=True ";            SqlConnection sConn = new SqlConnection(connSting);            try            {                sConn.Open();            }            catch (Exception ex)            {                Console.WriteLine("鏈接錯(cuò)誤:" + ex.Message);            }            string sqlMessage=null;            sqlMessage = "select * from student";            SqlCommand sCmd = new SqlCommand(sqlMessage, sConn);            SqlDataReader sdr = null;            try            {                sdr = sCmd.ExecuteReader();                            Console.WriteLine(" 姓名   性別   年齡 ");                while (sdr.Read())                {                    Console.WriteLine(sdr["name"] +""+ sdr["sex"]+"" + sdr["age"]);                }                sConn.Close();            }            catch (Exception ex)            {                Console.WriteLine(ex.Message);            }            Console.ReadLine();        }    }}

3.運(yùn)行結(jié)果將會(huì)顯示數(shù)據(jù)庫(kù)中的數(shù)據(jù)


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 海淀区| 西贡区| 宁德市| 兰考县| 扎赉特旗| 青铜峡市| 宁蒗| 天峻县| 印江| 南木林县| 专栏| 陕西省| 乌鲁木齐市| 新绛县| 霍林郭勒市| 江山市| 曲松县| 正蓝旗| 东乡县| 卢龙县| 四会市| 满洲里市| 景宁| 长汀县| 东辽县| 刚察县| 庆元县| 常宁市| 巴楚县| 宁海县| 大宁县| 毕节市| 绿春县| 长春市| 农安县| 荆州市| 东台市| 清水河县| 五家渠市| 大安市| 余姚市|