C#连接SQLServer数据库

来源:互联网 发布:知恩于心 感恩于行 编辑:程序博客网 时间:2024/06/05 15:19
public string GetData()        {            try            {                SqlConnection sqlConnection =                    new SqlConnection(                        "Data Source=127.0.0.1;Initial Catalog=SalesERPDB;Integrated Security=True;User Id=sa;Password=123456");                sqlConnection.Open();                SqlCommand sqlCommand = new SqlCommand();                sqlCommand.Connection = sqlConnection;                sqlCommand.CommandType = CommandType.Text;                sqlCommand.CommandText = "select FirstName from TblEmployee";                return sqlCommand.ExecuteScalar().ToString();            }            catch (Exception ex)            {                return ex.ToString();            }        }
原创粉丝点击