c# ExecuteScalar使用

来源:互联网 发布:巫师3新手必知 编辑:程序博客网 时间:2024/06/05 19:50

一 : 结果


二: 代码

using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.SqlClient;
namespace list
{
   
    class Program
    {
        static void Main(string[] args)
        {
            string connectionString = "server=.;uid=sa;pwd=123456;database=ceshifu;Connect Timeout=100;";
            string sql = "SELECT top 1 cpClientId from SaClientPersonal where cpCredentialsId='360121199911061234'";
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = sql;
            SqlDatabase database = new SqlDatabase(connectionString);
             object objValue =  database.ExecuteScalar(cmd);
             int clientid = (int)objValue;
             Console.WriteLine(clientid);
            Console.ReadLine();
           
        }
    }
}


原创粉丝点击