C# App.config 数据库操作

app.config

  <appSettings>
    <add key="DBConnectionString" value="server=.\SQLEXPRESS;database=cdm;User Id=sa;pwd=123abc!"/>

  </appSettings>


.cs

using System.Data.SqlClient;
using System.Configuration;

////////////////////

 using (SqlConnection connection = new SqlConnection(ConfigurationSettings.AppSettings["DBConnectionString"]))
            {

                SqlCommand command = new SqlCommand("select max(spid) from spkfk ", connection);
                command.Connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                   ////////////////
                }


 

你可能感兴趣的:(C# App.config 数据库操作)