C#连接SQLServer数据库

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();
            }
        }

你可能感兴趣的:(C#,数据库,string,c#)