最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

adonet基礎(chǔ)示例分享(adonet連接數(shù)據(jù)庫)

 更新時(shí)間:2014年04月02日 10:05:56   作者:  
這篇文章主要介紹了adonet基礎(chǔ)示例分享(adonet連接數(shù)據(jù)庫),需要的朋友可以參考下
adonet基礎(chǔ)示例分享
復(fù)制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.SqlClient;

namespace ADONET基礎(chǔ) {
    /// <summary>
    /// Window1.xaml 的交互邏輯
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            ////using() 自動關(guān)閉數(shù)據(jù)庫,回收資源。
            ////SqlConnection為建立和數(shù)據(jù)庫連接的對象。
            //using (SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=myself;User Id=sa;Password=123;"))
            //{
            //    conn.Open();//打開連接
            //    //通過連接,創(chuàng)建一個(gè)向數(shù)據(jù)庫發(fā)命令的對象SqlCommand
            //    using (SqlCommand cmd = conn.CreateCommand())//釋放資源。
            //    {
            //        //CommandText為要執(zhí)行的SQL的語句
            //        cmd.CommandText = "Insert into student(學(xué)號,姓名) values(110,'張五')";
            //        //ExecuteNonQuery一般用來執(zhí)行Update Delete Insert 語句。
            //        cmd.ExecuteNonQuery();//執(zhí)行上面的SQL語句。
            //    }
            //}

            using (SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=MyTest;User Id=sa;Password=123;"))
            {
                conn.Open();
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    //cmd.CommandText = "select count(*) from student where 入學(xué)成績<570";
                    //cmd.CommandText = "select count(*) from student where 入學(xué)成績<570";
                    ////ExecuteScalar一般用來執(zhí)行有且只有一行一列返回值的SQL語句。
                    //int i = (int)cmd.ExecuteScalar();
                    //MessageBox.Show(i+"人成績小于570分");
                    cmd.CommandText = "Insert into T_Student(Name,Age) output inserted.Id values('張顧',18);";
                    long i = (long)cmd.ExecuteScalar();
                    MessageBox.Show("Id為"+i);
                }
            }
            MessageBox.Show("執(zhí)行完成");
        }
    }
}

相關(guān)文章

最新評論

宁南县| 贡嘎县| SHOW| 龙岩市| 崇州市| 长宁县| 吴堡县| 林芝县| 金坛市| 仲巴县| 门头沟区| 阿拉尔市| 石嘴山市| 罗山县| 清水河县| 吴忠市| 建湖县| 汝南县| 新沂市| 贵溪市| 九寨沟县| 双城市| 运城市| 松原市| 池州市| 阳新县| 隆尧县| 青河县| 饶平县| 沁阳市| 龙州县| 湟源县| 田林县| 益阳市| 富锦市| 称多县| 鞍山市| 凯里市| 洛南县| 观塘区| 平乡县|